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,418 results
instfix -icq | grep 5300-07_AIX_ML | grep ":-:"
2009-03-11 12:34:18
User: deltwalrus
Functions: grep

This will let you know what filesets or fixes (if any) are missing in order to be considered "at" a given technology level in AIX.

find . -name *DS_Store -exec echo rm {} \;
2009-03-11 11:30:55
User: dgomes
Functions: echo find rm

This is quite usefull in Unix system share via NFS or AppleTalk with OSX clients that like to populate your filesystem with these pesky files

ctrl-x e
2009-03-11 09:26:05
User: fool

Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.

sudo lsof -i :<port>
vim $( ls -t | head -n1 )
rpm2cpio /path/to/file.rpm | cpio -i -d
2009-03-10 21:02:14
User: atoponce
Functions: cpio

This assumes you have the 'rpm', 'rpm2cpio' and 'cpio' packages installed. This will extract the contents of the RPM package to your current directory. This is useful for working with the files that the package provides without installing the package on your system. Might be useful to create a temporary directory to hold the packages before running the extraction:

mkdir /tmp/new-package/; cd /tmp/new-package
echo -n "string" | md5sum -
2009-03-10 21:01:36
User: cryptema
Functions: echo md5sum

A useful way to generate the MD5 hash for a string by command line

for i in $(ls *.od{tp}); do unoconv -f pdf $i; done
function cdls { cd $1; ls; }
2009-03-10 19:13:47
User: joem86
Functions: cd
Tags: terminal

After typing cd directory [enter] ls [enter] so many times, I figured I'd try to make it into a function. I was surprised how smoothly I was able to integrate it into my work on the command line.

Just use cdls as you would cd. It will automatically list the directory contents after you cd into the directory. To make the command always available, add it to your .bashrc file.

Not quite monumental, but still pretty convenient.

for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done
2009-03-10 17:51:19
Functions: mv sed

Jan Nelson from Grockit came up with this for us when we needed to rename all of our fixtures.

svn status | grep ^? | awk '{print $2}' | xargs rm -rf
2009-03-10 17:01:40
User: Highwayman
Functions: awk grep rm xargs

Removes all unversioned files and folders from an svn repository. Also:

svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf

will remove those files which svn status ignores. Handy to add to a script which is in your path so you can run it from any repository (a la 'svn_clean.sh').

grep Mar/2009 /var/log/apache2/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head
echo "\"\e[5~\": history-search-backward" >> ~/.inputrc
2009-03-10 15:32:52
User: silbermm
Functions: echo

What this does is, if I type ?ssh ? then hit the page-up key, it will complete the line to the last time in my history file that I typed ssh. Hitting page up again will go to the 2nd to last time I typed it. Incredibly handy if you ever type the same commands more than once.

credit goes to http://www.sharms.org/blog/2009/03/10/make-your-bash-shell-cool-again/

echo "\"\e[6~\": history-search-forward" >> ~/.inputrc
ssh -NL 2000:remotehost:22 remotehost
rename .JPG .jpg *.JPG
2009-03-10 15:07:24
User: psytek
Functions: rename

This will change all files ending in .JPG to .jpg and will work with any file extension

ssh -fX <user>@<host> <program>
2009-03-10 15:02:35
User: prayer
Functions: ssh
Tags: ssh
ssh -X example.org xeyes

The SSH server configuration requires:

X11Forwarding yes # this is default in Debian

And it's convenient too:

Compression delayed

gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
2009-03-10 14:53:33
User: prayer
Tags: gtk

Then, you can assign new accels to GTK menu actions pressing the keys while the option is active.

echo -n $mypass | md5sum | awk {'print $1'}
2009-03-10 13:12:21
User: tororebelde
Functions: awk echo md5sum

This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script

unalias ls
2009-03-10 11:23:31
Functions: unalias

Sometimes you have a situation where you cannot properly see the ls output when you are using a terminal w/a dark background. Usually bash has ls aliased to use colors, and you can easily get ls to use the default foreground color via simply unaliasing the command.

awk '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }'
2009-03-10 05:35:22
User: MSBF
Functions: awk printf

works the same as R's t()

yes "text" | annoying_installer_program # "text" defaults to the letter y
set -o noclobber
2009-03-10 01:39:18
User: vududevil
Functions: set

Use set +o noclobber and you will be able to replace files again

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

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.

tar cf - . | (cd /new/dir; tar xvf -)
2009-03-09 20:30:34
User: jauderho
Functions: cd tar

Add z to the flags to enable compression.