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.


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:



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.




Commands using sudo from sorted by
Terminal - Commands using sudo - 418 results
sudo service vpnclient_init start
2010-11-10 20:18:08
User: mariusbutuc
Functions: sudo


[1] download the CISCO VPN client for linux: http://tuxx-home.at/archives/2007/09/24/T15_26_49/

[2] apply this ciscpo VPN patch: http://bit.ly/linux_vpn_patch

[*] use command to start client

[*+1] After copying your profile file to /etc/opt/cisco-vpnclient/Profiles, connect using

vpnclient connect TORVPN-TCP
sudo chmod -x /usr/lib/notify-osd/notify-osd
2010-11-10 11:35:43
User: lokutus25
Functions: chmod sudo

Quick and dirty way to disable the Ubuntu notifications that can be quite annoying. It prevent the notify-osd to start so you need to logout Gnome or kill it by hand to take effect.

sudo find /usr/share/hunspell/ -lname '*' -delete
2010-11-07 15:11:02
User: atti
Functions: find sudo

When you right click a text box in Firefox and you have installed a few dictionaries you'll see a loooong list of spellcheckers. Most of them are duplicated (symlinks). This command deletes de duplicates and reduces the list.

set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2"
sudo dpkg -P $(dpkg -l | grep -i adobeair)
sudo -b xterm
2010-10-05 23:03:01
Functions: sudo

"The -b (background) option tells sudo to run the given command in the background." -- after it asks you for the password in the foreground.

sudo ls ; sudo gedit /etc/passwd &
2010-10-05 21:01:34
User: aporter
Functions: ls sudo

Take advantage of sudo keeping you authenticated for ~15 minutes.

The command is a little longer, but it does not require X (it can run on a headless server).

sudo -K
2010-10-05 12:44:26
User: b_t
Functions: sudo

By default sudo 'remembers' password for a few minutes, so that you do not need to re-enter password for a series of sudo commands that might follow within a short time duration.

However, sometime you might want sudo to instantly 'forget' the password.

(Next sudo command will need you to reenter the password)

Credit: I first learned this while listening to one of the 'tuxradar' podcast.

sudo hwinfo --framebuffer
2010-10-03 14:45:02
User: hute37
Functions: sudo

look at /boot/grub/menu.lst for somethig like:

## additional options to use with the default boot option, but not with the

## alternatives

## e.g. defoptions=vga=791 resume=/dev/hda5

## defoptions=vga=795

# defoptions=vga=873

## altoption boot targets option

## multiple altoptions lines are allowed

## e.g. altoptions=(extra menu suffix) extra boot options

## altoptions=(recovery) single

# altoptions=(verbose mode) vga=775 debug

# altoptions=(console mode) vga=ask

# altoptions=(graphic mode) quiet splash

# altoptions=(recovery mode) single

vga=(decimal value) is framebuffer mode

sudo youtube-dl -U
2010-10-02 12:51:46
Functions: sudo

If you update youtube-dl from the repos, it becomes out-of-date quickly. Luckily, it can auto-update.

sudo du -sm * | sort -n
2010-09-24 17:56:41
User: wabi
Functions: du sort sudo

sudo is optional, but to find out about all files, it is nice, or else run as superuser, ie: su -c 'du -sm * | sort -n'

echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
2010-09-21 10:24:42
User: bzaman
Functions: echo sudo tee

We sometimes need to change kernel parameters by echoing the file . This needs root privilege and if we do it using sudo like this , it fails

sudo echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

-bash: /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor: Permission denied

We can achieve this with the tee command by just doing sudo without logging as root user


sudo nvram boot-args="-v"
echo "savedefault --default=2 --once" | grub --batch; sudo reboot
tr '\000' '\377' < /dev/zero | dd bs=512 count=200000 status=noxfer | pipebench | sudo dd of=/dev/sdx
2010-08-31 15:38:27
User: Gliktch
Functions: dd sudo tr

Note: Replace 200000 with drive bytes/512, and /dev/sdx with the destination drive/partition. ;)

Note: You may need to install pipebench, this is easy with "sudo apt-get install pipebench" on Ubuntu.

The reason I hunted around for the pieces to make up this command is that I wanted to specifically flip all of the bits on a new HDD, before running an Extended SMART Self-Test (actually, the second pass, as I've already done one while factory-zeroed) to ensure there are no physical faults waiting to compromise my valuable data. There were several sites that came up in a Google search which had a zero-fill command with progress indicator, and one or two with a fill-with-ones command, but none that I could find with these two things combined (I had to shuffle around the dd command(s) to get this to happen without wasting speed on an md5sum as well).

For reference, these are the other useful-looking commands I found in my search:

Zero-fill drive "/dev/sdx", with progress indicator and md5 verification (run sudo fdisk -l to get total disk bytes, then divide by 512 and enter the resulting value into this command for a full wipe)

dd if=/dev/zero bs=512 count=<size/512> | pipebench | sudo tee /dev/sdx | md5sum

And this command for creating a file filled with ones is my other main source (besides the above command and man pages, that is - I may be a Linux newbie but I do read!):

tr '\000' '\377' < /dev/zero | dd of=allones bs=1024 count=2k

Hope someone finds this useful! :)


- Gliktch

sudo mdutil -a -i off
2010-08-26 16:34:20
User: ElAlecs
Functions: sudo

To re enable just change the "off" for "on"

sudo foremost -i /dev/sda -o /recovery
2010-08-19 22:27:41
User: vlan7
Functions: sudo

The above command assumes the lost data is on /dev/sda and you previously issued the following command to mount _another_ disk or partition (/dev/sdb1) on /recovery

sudo mount /dev/sdb1 /recovery

If you don't do this, the data could be overwrited!

foremost is a very powerful carving tool. By default foremost recovers all known file types. If you want to reduce the amount of files that are recovered you can specify the file type you are looking for. Read the man page to know the available file types.

i.e to recover JPEG pictures append to foremost the switch -tjpg

sudo tcpdump -i eth0 -n port 67 and 68
2010-08-18 19:36:06
User: wsv123456
Functions: sudo tcpdump

You don't need this command often and there are other ways to test output but if you want to be sure if your router and ethernet card are working this is one way.

sudo dmidecode -t processor
vi2() {for i in $@; do [ -f "$i" ] && [ ! -w "$i" ] && sudo vim $@ && return; done; vim $@}
2010-08-15 10:00:14
User: pipeliner
Functions: sudo vim
Tags: vim sudo

Like the http://www.commandlinefu.com/commands/view/6327/open-file-with-sudo-when-there-is-no-write-permission, but works (in zsh; my commandlinefu is not strong enough to understand why bash don't like it) with vim options, like -O, and many input files.

There could be other mistakes.

if test -w $1; then vim $1; else sudo vim $1; fi
2010-08-14 13:28:32
User: srepmub
Functions: sudo test vim
Tags: vim sudo tee

this avoids several VIM warnings, which I seem too stupid to disable: warning, readonly! and: file and buffer have changed, reload?!

sudo sh -c "apt-get update;apt-get dist-upgrade;apt-get autoremove;apt-get autoclean"
2010-08-13 16:12:18
User: l0b0
Functions: sh sudo

Gets you the latest of everything, and removes any remaining junk. The "sh -c" part is so that you'll only run a single sh command, so you won't get asked more than once for the password.

sudo pm-suspend
sudo /etc/acpi/sleep.sh sleep
2010-08-03 23:54:49
User: jmfork
Functions: sudo
Tags: sleep suspend

It suspends to RAM: you always need your batteries for the RAM but it saves time as there is no need to slowly archive everything on your hard disk.

It works fine with me but if anyone has a nicer way, please contribute.