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.

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





All commands from sorted by
Terminal - All commands - 12,273 results
sed ?s/[sub_str]/[sub_str]\n/g? [text_file] | wc -l
for i in $(find . -mtime +30); do mv $i old/; done
2014-02-05 01:24:45
User: valferon
Functions: find mv
Tags: bash file

Will move in that case every file in the current folder older than 30 days to the "old" folder

Replace "mv $i old/" by any command such as rm / echo to do something different.

du | sort -n | tail -11 | head
2009-03-04 16:06:34
User: phage
Functions: du sort tail

The pipe to head removes the listing of . as the largest directory.

for files in $(ls -A directory_name); do sed 's/search/replaced/g' $files > $files.new && mv $files.new $files; done;
2009-05-07 20:13:07
User: bassu
Functions: ls mv sed

Yeah, there are many ways to do that.

Doing with sed by using a for loop is my favourite, because these are two basic things in all *nix environments. Sed by default does not allow to save the output in the same files so we'll use mv to do that in batch along with the sed.

TIMEUNIT=$( cat a | grep -n "timescale" | awk -F ":" '{ print $1 } ' )
chown -R webuser:webgroup /var/www/vhosts/domain.com/httpdocs
gconftool-2 --set /apps/metacity/global_keybindings/panel_main_menu --type string "Super_L"
synclient TouchPadOff=1
synclient TouchPadOff=0
grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}' OR USE ALTERNATE WAY awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'
2009-03-05 07:28:26
User: rommelsharma
Functions: awk grep

grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}'


awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'

In this example, we are having a text file that is having several entries like:


c1 c2 c3 c4

this is some data

HOME /dir1/dir2/.../dirN/somefile1.xml

HOME /dir1/dir2/somefile2.xml

some more data


for lines starting with HOME, we are extracting the second field that is a 'file path with file name', and from that we need to get the filename only and ignore the slash delimited path.

The output would be:



(In case you give a -ive - pls give the reasons as well and enlighten the souls :-) )

cd !$
2009-05-08 09:48:14
Functions: cd

During this operation :

# mv Joomla_1.5.10-Stable-Full_Package.zip /var/www/joomla/

I invoke /var/www/joomla/ as last command argument. To change in this directory I can use

# cd !$

So I go to


gzip *
2010-03-29 10:58:40
User: funky
Functions: gzip
Tags: gzip

Should do exactly the same - compress every file in the current directory. You can even use it recursively:

gzip -r .
tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
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).

list the naming contexts of a directory server (no need to search in config files)
pon dsl-provider
grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//"
2009-04-09 12:49:01
Functions: cut grep sed uniq xargs

Linux : these script enable you to edit multiple files and remove exact phrase from multiple files

ls .[!.]*
2009-09-29 13:50:13
User: danam
Functions: ls

Although rm is protected against it, there are many commands that would wreak havoc on entering the obvious ".*" to address "dot-files". This sweet little expression excludes the dirs "." and ".." that cause the problems.

for ((i=0;i<5;i++)) ; do xpenguins & done
netstat -ie
grep -sq "" /etc/lsb-release && lsb_release -rd
2009-02-17 05:21:20
User: int19h
Functions: grep

grep -sq "" filename && command

grep can be used in combination with && to run a command if a file exists.

for i in $(seq 5); do xpenguins & done
for i in `ps -ef | grep tracker | awk '{print $8}' | cut -d'/' -f4 | grep -v grep`; do killall -9 $i; done
2011-12-04 13:20:19
User: alienone
Functions: awk cut grep killall

* ps -ef # list running processes

* grep string

* pull the process names from 8th field

* cut and delimiter '/'

* print 4th field

* get rid of trailing grep

* for loop killall -9 $i which is the process name

bvi [binary-file]
2009-03-24 15:30:50
User: haivu
Tags: edit

bvi is your vi for binary editing. If your system does not have it, you can get it from


xmlstarlet sel --net -t -o "Terrorist threat level: " -v //@CONDITION http://is.gd/wacQtQ