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,274 results
vim `find . -iname '*.php'`
2011-05-11 01:19:28
User: wsams
Functions: vim

In this case, we'll be editing every PHP file from the current location down the tree.

You can show all the files in the vim buffer with :buffers which outputs something like,


1 %a "./config/config.php" line 1

2 "./lib/ws-php-library.php" line 0

3 "./lib/css.php" line 0

4 "./lib/mysqldb.class.php" line 0

5 "./lib/config.class.php" line 0

6 "./lib/actions.php" line 0

Press ENTER or type command to continue

If you'd like to edit ./lib/mysqldb.class.php for example, enter :b4 anytime you're editing a file. You can switch back and forth.

sudo killall -HUP mDNSResponder
2012-05-15 18:33:51
User: Xeno
Functions: killall sudo

Purges DNS cache of OS X.

dscacheutil -flushcache does not work since OS X 10.7.

xclip -sel clip < ~/.ssh/id_rsa.pub
mdfind 'kMDItemFSCreationDate >= $time.this_month'
2012-11-13 12:50:51
User: peter4512

This uses spotlight indices to find files that have recently been added. Other options include underscore separated versions of: this week, this month, this

year; today, yesterday.

curl ip.appspot.com
ethtool -S eth0 | egrep "(drop|disc|err|fifo|buf|fail|miss|OOB|fcs|full|frags|hdr|tso).*: [^0]"
2014-07-15 05:27:34
User: suprjami
Functions: egrep

A grep against ethtool to look for common errors and packet loss statistics which network drivers report in their private data, which is queried with ethool -S. This is the current grep used in xsos (https://github.com/ryran/xsos), which I originally contributed and has been improved by the community over time.

pkgchk -l -p <full path to the file>
2009-07-04 08:22:11
User: sengork
Tags: solaris

Find which package a file belongs to on Solaris along with it's packaging system metadata.

watch -d 'ls -l'
2009-09-03 20:12:36
User: 0disse0
Functions: watch
Tags: watch stats

To highlight the difference between screen updates

snarf http://foo.bar.com/picture.jpg
2009-09-23 04:22:57

It can transfer files through the http, gopher, finger, and ftp protocols without user interaction. It is small and fast.

sync; time `dd if=/dev/zero of=bigfile bs=1M count=2048 && sync`
for i in `ndd /dev/ip \? | awk '{ print $1 }' | egrep -v "ip6|status|icmp|igmp|\?"` ; do echo $i `ndd -get /dev/ip $i` ; done | grep -v \?
2010-02-15 12:32:33
User: felix001
Functions: awk echo egrep grep

This command is jsut for the main IP settings of ndd. if you need ip6 or icmp edit the text within the egrep inclusion area.

Felix001 - www.Fir3net.com

gnome-open . & disown
find /var/log/apache2 -name 'access.log*gz' -exec zcat {} \; -or -name 'access.log*' -exec cat {} \;
2010-06-19 08:35:12
User: recursiverse
Functions: cat find zcat

This command allows you to stream your log files, including gziped files, into one stream which can be piped to awk or some other command for analysis.

Note: if your version of 'find' supports it, use:

find /var/log/apache2 -name 'access.log*gz' -exec zcat {} + -or -name 'access.log*' -exec cat {} +
perl -le '$,=".";print map int rand 256,1..4'
tr -d '\\' | tr -d '\n'
cat ~/.ssh/id_rsa.pub | ssh tester@ "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:54
Functions: cat ssh

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

sudo usermod -s `which zsh` `whoami`
tar -cjf - $DIR | nc $HOST $PORT
2012-11-13 16:44:26
Functions: tar
Tags: netcat tar

Tar's up $DIR locally (w/bzip2) and sends remotely to $HOST:$PORT where netcat listens (using openbsd netcat). Start up receiving side command first, then execute this.

for i in {1..31}; do ls -1 *${YYYY}${MM}`printf "%02d" $i`* | wc -l; done
2013-07-26 07:08:04
User: Paulus
Functions: ls wc
Tags: bash Linux

RU: Найдет число файлов в папке по данной маске в цикле по дням месяца

CSS=$HOME/.config/google-chrome/Default/User\ StyleSheets/Custom.css sh -c 'test -f "$CSS.off" && mv "$CSS.off" "$CSS" || mv "$CSS" "$CSS.off"'
2013-10-06 00:38:00
User: Romero
Functions: mv sh

A very simple command to toggle Chrome?s default style sheet. It uses the test command to see if the "Custom.css.off" file exists, if so, it will become "Custom.css", and if not, "Custom.css" is moved to "Custom.css.off" Thus, swapping.

This is accomplished with "&&" and "||"

rename 's/\.sh//' ./*
2014-04-02 16:33:25
User: abhikeny
Functions: rename

The 'rename' command with the first argument as "'s/\.//'" and the second argument as "" will remove the specified extension from the filenames.

fn() { find . -iname "*$1*" -print; }
2014-07-15 05:30:59
User: suprjami
Functions: find

A simple bash function to the find command. I use this much more than find itself.

busybox nameif newname $(</sys/class/net/oldname/address)
2010-05-15 10:24:57
User: patrick2000
Functions: nameif

rename a network interface

e.g. make eth0 eth1 or vice versa

the interface needs to be down -> "/sbin/ifconfig oldname down"

ls -t1 $* | head -1 ;
2012-02-10 22:13:24
Functions: head ls

Returns the most recently modified file in the current (or specified) directory. You can also get the oldest file, via:

ls -t1 $* | tail-1 ;

tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
2012-05-15 21:56:46
User: pykler
Functions: python tail

Realtime lines per second in a log file using python ... identical to perl version, except python is much better :)