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 - 400 results
sudo socat TCP4-LISTEN:80,bind=,fork EXEC:'echo "HTTP/1.1 503 Service Unavailable";'
2011-05-02 19:31:56
User: adelie42
Functions: sudo

Normally when a site is blocked through /etc/hosts, traffic is just being redirected to a non-existent server that isn't going to respond. This helps get your point across a little more clearly than a browser timeout.

Of course you could use any number of codes: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Obviously, this command can be added to init-rc.d, and more sophisticated responses can be given. Seems noteworthy to mention that the information sent from the browser can be parsed using the bash READ builtin (such as 'while read -t 1 statement; do parsing'), and the connection stays open until the script exits. Take care that you must use EXEC:'bash -c foo.sh', as 'execvp' (socat's method for executing scripts) invokes 'sh', not 'bash'.

echo "shutdown -h now" | sudo at now + 4 hours
2011-05-02 15:29:48
User: depesz
Functions: at echo sudo

Benefit is that it doesn't make you keep the terminal open.

sudo bash -c 'echo "GRUB_INIT_TUNE=\"480 165 2 165 2 165 3 554 1 587 1 554 2 370 1 554 1 523 2 349 1 523 1 494 3 165 2 165 2 165 2\"" >> /etc/default/grub && update-grub'
2011-05-02 12:06:49
User: slayer_ftw
Functions: bash sudo

I'll let Slayer handle that. Raining Blood for your pleasure.

sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
2011-04-25 05:19:57
User: Bonster
Functions: awk sed sudo

Same as 7272 but that one was too dangerous

so i added -P to prompt users to continue or cancel

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

echo "GRUB_INIT_TUNE=\"1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2\"" | sudo tee -a /etc/default/grub > /dev/null && sudo update-grub
sudo apt-get install linux-headers-$(uname -r)
sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key |sudo apt-key add -; done
2011-03-30 08:18:54
User: Bonster
Functions: echo gpg grep sed sudo

You can choose these mirror servers to get gpg keys, if the official one ever goes offline







wwwkeys.en.pgp.net #(replace with your country code fr, en, de,etc)

sudo aptitude purge ~ilinux-image-\[0-9\]\(\!`uname -r`\)
2011-03-28 13:54:21
User: ootync
Functions: sudo

Removes piling kernels from /boot, save the current one.

This command DOES NOT remove the 'linux-image-generic' package, so you'll continue getting kernel updates

sudo pacman -Rns packagename
2011-03-20 21:07:14
User: ibnarrashid
Functions: sudo

Removes the package, 'packagename' in the example ,from your system. '-R' is the actual removal option, 'n' is for removing backup configuration files saved by pacman, and 's' is for removing the dependencies of the given package which are not required by other packages. pacman does not remove configuration files, etc. created by the package.

sudo pacman -Scc
2011-03-20 20:57:42
User: ibnarrashid
Functions: sudo

Clears the package cache of all packages, installed and uninstalled packages. Do NOT USE if you might want to downgrade a package later.

sudo pacman -Sc
2011-03-20 20:55:32
User: ibnarrashid
Functions: sudo

Clears the package cache of all uninstalled packages. Does not remove package configuration files in user's home directory.

sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
2011-03-20 20:33:35
User: ibnarrashid
Functions: sudo

Requires 'reflector' package from official repository. '5' in the example is the number of mirrors you want in the mirrorlist, could be other numbers of course.

sudo -i; add-apt-repository ppa:webupd8team/sublime-text-2; apt-get update; apt-get install sublime-text-2
2011-03-16 23:57:41
User: xmonkey
Functions: install sudo

This is the first version of the Sublime Text 2 packaging so there might be bugs.

sudo scutil --set HostName MY_NEW_HOSTNAME
sudo tcpdump -i eth0 -s 65535 -A -ttt port 11211
sudo update-alternatives --config java
2011-03-07 23:43:52
User: mccalni
Functions: sudo
Tags: java

You have openjdk and sun java installed. Many of your java plugins will not work properly. Something called IcedTea (the java web plugin) keeps crashing. Run this and select sun java to use sun java.

fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else sudo ln -f ${line// .*/} $file; fi; done; done
sudo arp-scan -l
2011-02-21 21:58:27
Functions: sudo
Tags: Arp arp-scan

A much quicker and (not dirtier) option. use the man page for help. On linux/ubuntu you will need to `sudo apt-get -y install arp-scan`.

sudo usermod -a -G adm "$(whoami)"
trickle sudo apt-get update -y
sudo apt-get -o Acquire::http::Dl-Limit=20 -o Acquire::https::Dl-Limit=20 upgrade -y
2011-02-14 05:24:49
User: ruslan
Functions: sudo

in Debian-based systems apt-get could be limited to the specified bandwidth in kilobytes using the apt configuration options(man 5 apt.conf, man apt-get). I'd quote man 5 apt.conf:

"The used bandwidth can be limited with Acquire::http::Dl-Limit which accepts integer values in kilobyte. The default value is 0 which deactivates the limit and tries uses as much as possible of the bandwidth..."

"HTTPS URIs. Cache-control, Timeout, AllowRedirect, Dl-Limit and proxy options are the same as for http..."

sudo hping3 -TV --tr-stop -n -2 -p 53 ns1.server.tld
2011-01-14 10:12:37
User: forcefsck
Functions: sudo

-T = traceroute

-V = verbose

--tr-stop = exit when target is reached

-n = don't do reverse lookups (faster)

-2 = udp

-p 53 = destination port 53 (dns), change to your needs

Useful when trying to debug a network with complex routing rules and/or multiple gateways.

find /path/to/folder/ -mindepth 1 -maxdepth 2 -name "*,v" -exec sudo rlog -L -R {} \;
sudo lsof -p1234 | grep -E "(3r|4w).*REG"
2011-01-11 19:45:24
User: zlemini
Functions: grep sudo

If you spot a dubious looking cp command running you can use this command to view what is being copied and to where.

1234 is the PID of the cp command being passed to the lsof utility.

3r.*REG will display the file/directory that is being read/copied.

4w.*REG will display the destination it is being written to.

echo <percentage> | sudo dd of=/proc/acpi/video/VGA/LCD/brightness
2011-01-05 03:57:58
User: alperyilmaz
Functions: dd echo sudo
Tags: dd echo

An alternative which does not require to be root