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 - 415 results
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
2009-06-19 10:11:00
User: plasticdoc
Functions: sed sudo xargs
6

will purge:

only installed apps: /^ii/!d

avoiding current kernel stuff: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d

using app names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/

avoiding stuff without a version number: /[0-9]/!d

sudo ifconfig eth0 hw ether 00:01:02:03:04:05
2009-06-04 09:02:35
User: momitov
Functions: ifconfig sudo
6

eth0 = the name of the interface

00:01:02:03:04:05 = the new mac adresse

the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile
2009-05-27 21:10:50
User: dcabanis
Functions: dd mkswap sudo swapon
18

Create a temporary file that acts as swap space. In this example it's a 1GB file at the root of the file system. This additional capacity is added to the existing swap space.

sudo dmidecode -t 5,16
sudo pmset schedule sleep "08/31/2009 00:00:00"
2009-05-14 09:31:32
User: hobzcalvin
Functions: sleep sudo
4

Schedule your Mac to sleep at any future time.

Also wake, poweron, shutdown, wakeorpoweron. Or repeating with

sudo pmset repeat wakeorpoweron MTWRFSU 7:00:00

Query with

pmset -g sched

Lots more at http://www.macenterprise.org/articles/powermanagementandschedulingviathecommandline

function ec() { ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var; }
2009-05-14 04:34:26
Functions: cd sudo
0

ec commits changes to etckeeper

must have etckeeper installed with bzr to use this

place inside bashrc

can be used from any directory to commit changes

sudo shred -zn10 /dev/sda
2009-04-30 13:02:43
User: dcabanis
Functions: shred sudo
-2

Shred can be used to shred a given partition or an complete disk. This should insure that not data is left on your disk

sudo vol_id -u /dev/sda1
2009-04-30 01:40:58
User: agentk
Functions: sudo
3

Shows the UUID of a filesystem or partition that can be used in kernel root options and in fstab.

Run it without the -u option to generate more information. eg:

~/ sudo vol_id /dev/sda2

ID_FS_USAGE=other

ID_FS_TYPE=swap

ID_FS_VERSION=2

ID_FS_UUID=27fca13d-97b7-4d28-882c-6d03353f0a82

ID_FS_UUID_ENC=27fca13d-97b7-4d28-882c-6d03353f0a82

ID_FS_LABEL=

ID_FS_LABEL_ENC=

sudo pmset -a hibernatemode 1
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 *