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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



All commands from sorted by
Terminal - All commands - 12,422 results
aptitude show $PROGRAM | grep Vers
2009-02-27 23:24:37
User: aabilio
Functions: grep

Output: Version 3.2-0 (for example if you type # aptitude show bash | grep Vers

Depends on the language of your distribution, because the name of the word "Version" in other languages may be different.

sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
2009-02-27 20:23:37
User: bandit36
Functions: dd sudo
Tags: backup dd

This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the "if" & "of" locations.

sudo dd if=/media/disk/backup/sda.backup of=/dev/sda

Alternatively, you can use an SSH connection to do your backups:

dd if=/dev/sda | ssh [email protected] dd of=~/backup/sda.backup
rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * [email protected]:/path
2009-02-27 19:58:02
User: sudopeople
Functions: rsync
Tags: svn exclude

rsyncs files to a server excluding listed files

also a file can be used to exclude common exclude rules and/or to exclude a ton of files, like so:

rsync --exclude-from '~/.scripts/exclude.txt'

where exclude.txt has one rule per line:



write user anytext
ifconfig | awk '/inet / {print $2}'
2009-02-27 17:05:08
User: haivu
Functions: awk ifconfig

On the Mac, the format ifconfig puts out is little different from Linux: the IP address is space separated, instead of colon. That makes parsing the IP address easier. See releated command for Linux/Unix:


xmodmap -e "remove Lock = Caps_Lock"
2009-02-27 16:44:22
User: mzandrew

a quick one-line way to disable caps lock while running X.

vim -p file1 file2 ...
2009-02-27 16:43:59
User: haivu
Functions: vim
Tags: vim

Edit the files, each in a separate tab. use gT and gt to move to the left- and right-tab, respectively. to add another tab while editing, type ':tabe filename'

ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done
grep "FOUND" /var/log/squidclamav.log | awk '{print $5"-"$2"-"$3","$4","$11}' | sed -e 's/\,http.*url=/\,/g' | sed -e 's/&/\,/g' | sed -e 's/source=//g' |sed -e 's/user=//g' | sed -e 's/virus=//g' | sed -e 's/stream\:+//g' | sed -e 's/\+FOUND//g'
2009-02-27 13:28:18
User: nablas
Functions: awk grep sed

This command will list a CSV list of infected files detected by clamav through squidclamav redirector.

awk 'BEGIN {FS=","} {loc = $4, val=$5; getline < "f0001ch1.csv"; print loc,val,$5}' f0001ch2.csv > data
2009-02-27 13:01:16
User: Masse
Functions: awk

Parses tektronic given csv files for both channel 1 and channel 2 and joins them together. Can be easily used by gnuplot after that.

rpm -qif `which more`
2009-02-27 08:59:07
User: alcik
Functions: rpm
Tags: rpm which

Replace 'more' command with any command which is in your PATH.

ls -ld **/*(/)
ls -ld *(/)
git commit --amend
2009-02-27 04:42:44
Tags: git

It's pretty common to forgot to commit a files, be it a modification, or a brand new file.

If you did forget something, git add the files you want, and then git commit --amend. It will essentially redo the last commit, with the changes you just added. It seeds the commit message with the last commit message by default.

You probably shouldn't do this if you've already pushed the commit.

alias trash="rm -fr ~/.local/share/Trash"
2009-02-27 01:55:30
Functions: alias

Force empties the user trash

dpkg-reconfigure -phigh xserver-xorg
git rm $(git ls-files --deleted)
2009-02-26 21:21:02
Functions: rm
Tags: git

This command handles git rm'ing files that you've deleted.

$ cat /etc/*-release
ls -l | grep ^d
2009-02-26 20:28:10
User: sysadmn
Functions: grep ls

Show only the subdirectories in the current directory. In the example above, /lib has 135 files and directories. With this command, the 9 dirs jump out.

sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
2009-02-26 20:22:57
User: sysadmn
Functions: sort

Sort a list of IPV4 addresses in numerical order. Great as a filter, or within vim using !}

git diff --cached
sort -bdf
2009-02-26 19:55:41
User: sysadmn
Functions: sort

Often, when sorting you want the sort to ignore extraneous characters. The b, d, and f tell sort to ignore leading blanks, use 'dictionary order' (ignore punctuation), and ignore (fold) case. Add a "u" if you only want one copy of duplicate lines.

This is a great command to use within vim to sort lines of text, using !}sort -bdf

perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`
2009-02-26 19:14:39
User: adampbell
Functions: perl

Finds the string in every file in an entire directory and all its subdirectories and replaces it with a new string. Especially useful when changing a machine's IP address or hostname - run it on /etc.

time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done
2009-02-26 18:51:29
User: jcgam69
Functions: printf read time

Old snapshots can cause problems. It's best to remove them when finished. I use this script to remove all snapshots. The "while read" command is necessary because my vm names contain spaces. The "time" command reports how long the process runs.

for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done
2009-02-26 16:45:04
User: dbart
Functions: echo

I use this command on my machines running VMware Server to print out the state of all registered Virtual machines.