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.

Universal configuration monitoring and system of record for IT.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,403 results
2012-04-16 21:18:27
User: khopesh
Functions: cd
Tags: cd

This is like `cd -` but doesn't echo the new directory name, which is preferable (to me) for an alias, e.g.

alias cdo="cd $OLDPWD"
pkill -f foo
2009-02-05 16:12:53
User: archlich

Be careful when issuing this command, it may kill unwanted processes!

To only search on the process name don't use the argument -f, pkill foo

for x in *.dat;do sort -k 3 $x >tmp && mv -f tmp $x;done
2010-07-07 07:57:37
User: rajarshi
Functions: mv sort
Tags: sorting

We normally get tasks in which one has to sort a data file according to some column. For a single file say foo, we would use

sort -k 3 foo >tmp && tmp foo

The for loop is useful when we have to do it on a number of files.

yes 1 | fdupes -rd $folder
2011-06-02 18:15:24
User: torrid
Functions: yes
Tags: deduplicate

This command deletes all but the first occurrence of a duplicate file in one or more folders.

nautilus "$pwd"
awk '{print(substr($0,1,5))}' file
2009-10-05 18:58:49
Functions: awk

Consider this file :




with awk

hello to


I can use awk substring to laminate words :







Similar to http://www.commandlinefu.com/commands/view/2000/laminate-files-line-by-line

cut -d: -f1 /etc/passwd | sort
lynx -dump http://domaim.com | egrep -o -e 'http://[/0-9a-z.]+html'
netstat -lntp
awk 'BEGIN { srand(); print rand() }'
2010-08-07 14:33:12
User: dennisw
Functions: awk
Tags: random number

2d6 dice:

awk 'BEGIN { srand(); a=int(rand()*6)+1; b=int(rand()*6)+1; print a " + " b " = " a+b }'

3 + 6 = 9

ls /dev/disk/by-uuid/ -alh
cat `ls -r /sys/class/net/*/address` | sort -u
script -t 2> timing.txt -a session.txt ; Run some commands here; exit; scriptreplay timing.txt session.txt
type -a python
f -f -e mplayer movie
2011-12-09 02:58:41
User: clvv

This is one use case of `f`. You need to install `f`(https://github.com/clvv/f) for this to work. With f, you can access any file by only typing some of its name regardless of where you are. f is inspired by autojump and z.

ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
psg(){ ps aux | grep -E "[${1:0:1}]${1:1}|^USER"; }
2015-01-01 00:12:45
User: flatcap
Functions: grep ps
Tags: grep function ps

Function that searchs for process by its name:

* Shows the Header for reference

* Hides the process 'grep' from the list

* Case sensitive

The typical problem with using "ps | grep" is that the grep process shows up the in the output.

The usual solution is to search for "[p]attern" instead of "pattern".

This function turns the parameter into just such a [p]attern.

${1:0:1} is the first character of $1


${1:1} is characters 2-end of $1
tar -pczf archive_name.tar.gz /path/to/dir/or/file
2009-07-17 19:53:02
User: ryuslash
Functions: tar
Tags: bash tar gzip

Create a single tar.gz archive

I know it's a very basic one, but it's one I keep forgetting.

locate searchstring | xargs grep foo
2009-04-16 12:51:24
User: zimon
Functions: grep locate xargs
Tags: grep locate

Greps located files for an expression.

Example greps all LaTeX files for 'foo':

locate *.tex | xargs grep foo

To avoid searching thousands of files with grep it could be usefull to test first how much files are returned by locate:

locate -c *.tex
for i in 192.168.1.{61..71};do ping -c 1 $i &> /dev/null && echo $i;fi;done
2009-08-26 06:04:24
User: AlecSchueler
Functions: echo ping
Tags: Network ssh bash

If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.

file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3
2009-09-11 16:43:27
Functions: cut file grep nl tail

Not as far off as you thought, now is it?

-mac fanboy

IP=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 2 | cut -d " " -f 1`;SUBNET=`ifconfig eth0 | grep "inet addr:" | ips |cut -d ":" -f 3 | cut -d " " -f 1`;RANGE=`ipcalc $IP/$SUBNET | grep "Network:" | cut -d ' ' -f 4`;echo $RANGE
ls -lah --color=always | most
2010-01-04 22:21:13
User: Code_Bleu
Functions: ls

Even though --color is an option for 'ls' it will not display in color when doing 'ls -lah --color=always | less' to have color output when doing a directory listing and piping it out to page through results, replace less with most.

To install most if not installed, run:

sudo apt-get install most

find . -type f -exec sed -i 's/gw10./gw17./g' {} \;
cowsay -l | sed '1d;s/ /\n/g' | while read f; do cowsay -f $f $f;done