Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using sudo from sorted by
Terminal - Commands using sudo - 406 results
sudo installer -pkg /Volumes/someapp/someapp.mpkg -target /
2009-04-28 19:43:56
User: sud0er
Functions: sudo
Tags: osx
4

Installing most OSX apps is just a matter of dropping it in /Applications, either GUI-wise or with cp -r. However, many packages are distributed in "mpkg" format, and those have to be installed with an installer. If you don't want to go to the trouble of firing up VNC to install an mpkg, you can use the "installer" command.

This will install an application from a .mpkg it to /Applications system-wide. To install a program for just one user, replace "-target /" with "-target username".

sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`
sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
2009-04-28 10:34:42
User: kelevra
Functions: awk grep sudo
Tags: awk apt-get dpkg
-4

Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this.

for i in /sys/class/net/*; do e=`basename $i`; echo "# $e"; sudo ethtool $e | grep -E "Link|Speed" ; done
2009-04-25 14:32:08
User: hank
Functions: echo grep sudo
Tags: Network Linux
0

Basically an improvement on an earlier ethtool command line.

sudo cat /dev/mem > /dev/dsp
for i in sys dev proc; do sudo mount --bind /$i /mnt/xxx/$i; done
2009-04-20 16:52:14
User: amosshapira
Functions: mount sudo
Tags: bash mount chroot
3

The command is useful when, e.g., booting an existing system with a rescue or installation CD where you need to chroot into the hard-disk and be able to do stuff which accesses kernel info (e.g. when installing Ubuntu desktop with LVM2 you need to mount and chroot the hard disk from a shell window in order to install packages and run initramfs inside chroot).

The command assumes that /mnt/xxx is where the chroot'ed environment's root file system on the hard disk is mounted.

sudo dpkg-reconfigure tzdata
2009-04-20 02:08:23
User: hank
Functions: sudo
Tags: Ubuntu time
3

Reconfigures time zone in Ubuntu, which I cannot figure out how to do through the GUI. Worked like a charm to set my time zone to CEST from EDT.

sudo cat /dev/vcs1 | fold -w 80
2009-04-15 08:49:48
User: animoid
Functions: cat fold sudo
16

This will view the console and assumes the screen is 80 characters wide.

Use /dev/vcs2 for the next virtual console.. etc.

sudo killall -9 pulseaudio; pulseaudio >/dev/null 2>&1 &
2009-04-11 20:18:35
User: hank
Functions: killall sudo
14

Ever since the switch to pulseaudio, Ubuntu users including myself have found themselves with no sound intermittently. To fix this, just use this command and restarts firefox or mplayer or whatever.

sudo update-alternatives --config editor
2009-04-09 18:26:52
User: mheadd
Functions: sudo
2

On Ubuntu, the default editor for visudo is nano. To change the editor to something else (e.g., vi) use this command.

sudo -i
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump
-2

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)

sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
2009-04-02 16:04:35
User: GinoMan2440
Functions: mount sudo vi
4

the middle command between the ; and ; is the vi commands that insert that line into the last line of the file, the esc with the carets is literally hitting the escape key, you have to have the smbfs package installed to do it, I use it to access my iTunes music on my mac from my linux PC's with amarok so I can play the music anywhere in the house. among other things, it allows you to access the files on that share from your computer anytime you're on that network.

man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
2009-04-01 06:48:48
User: jnash
Functions: awk man sed sudo xargs
4

Are there any creative pieces of music that can be created using beep and the shell? I'd love to hear it!

sudo firefox -install-global-extension /path/to/add-on
2009-03-28 11:11:12
User: cammarin
Functions: sudo
Tags: firefox
17

To install a theme use:

sudo firefox -install-global-theme /path/to/theme

You can get the .xpi or .jar file from the versions history on the add-on/theme page.

NOTE: may not work in your system (Debian-based is an example).

sudo chmod -R g=u-w,g+X *
on the listening side: sudo nc -lp 2022 | sudo tar -xvf - and on the sending side: tar -cvzf - ./*| nc -w 3 name_of_listening_host 2022
2009-03-27 09:59:33
User: smcpherson
Functions: sudo tar
Tags: netcat
-2

This is useful for sending data between 2 computers that you have shell access to. Uses tar compression during transfer. Files are compressed & uncompressed automatically. Note the trailing dash on the listening side that makes netcat listen to stdin for data.

on the listening side:

sudo nc -lp 2022 | sudo tar -xvf -

explanation: open netcat to -l listen on -p port 2022, take the data stream and pipe to tar -x extract, -v verbose, -f using file filename - means "stdin"

on the sending side:

tar -cvzf - ./*| nc -w 3 name_of_listening_host 2022

explanation: compress all files in current dir using tar -c create, -v verbose, -f using file, - filename - here means "stdout" because we're tar -c instead of tar -x, -w3 wait 3 seconds on stream termination and then end the connection to the listening host name_of_listening_host, on port 2022

function nuke() { if [ $(whoami) != "root" ] ; then for x in $@; do sudo apt-get autoremove --purge $x; done; else for x in $@; do apt-get autoremove --purge $x; done; fi }
2009-03-25 23:21:21
User: ruinbox
Functions: sudo
Tags: sudo apt-get
1

You can't stand programs x, y, and z. Remove all trace of their existence by adding this function to your config. It will remove the cruft, the settings, and such and such. This function doesn't even give a damn about you trying to remove programs that don't exist: it'll just for loop to the next one on your hit list.

wget -q http://xyz.gpg -O- | sudo apt-key add -
2009-03-25 12:18:36
User: gnuyoga
Functions: sudo wget
Tags: wget apt-key
4

when we add a new package to a aptitude (the debian package manager) we need to add the gpg, otherwise it will show warning / error for missing key

wget -q http://xyz.gpg -O- | sudo apt-key add -
2009-03-25 12:18:29
User: gnuyoga
Functions: sudo wget
Tags: apt-key
2

when we add a new package to a aptitude (the debian package manager) we need to add the gpg, otherwise it will show warning / error for missing key

ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
sudo zcat /var/log/auth.log.*.gz | awk '/Failed password/&&!/for invalid user/{a[$9]++}/Failed password for invalid user/{a["*" $11]++}END{for (i in a) printf "%6s\t%s\n", a[i], i|"sort -n"}'
2009-03-21 06:41:59
Functions: awk printf sudo zcat
22

Show the number of failed tries of login per account. If the user does not exist it is marked with *.

sudo dmidecode --type 17 | more
sudo lsof -i :<port>
sudo find / -iname "*.lproj" -and \! -iname "en*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
2009-03-09 22:08:45
User: asmoore82
Functions: find rm sudo tee xargs
3

This will get the job done in the most efficient way -

spawning only one `rm` process.

"On-the-fly" find data is displayed through `tee` and

you should have plenty of time to ctrl-c if needed before it's too late.

You may need to re-run this after major Software Updates.

To leave more languages in, add more ``-and \! -iname "lang*"'' statements:

sudo find / -iname "*.lproj" -and \! -iname "en*" -and \! -iname "spanish*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv

**Edit: note the 2nd sudo near the end of the pipeline - this is necessary.