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,230 results
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 :)

cat ~/.ssh/id_rsa.pub | ssh tester@ "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:55
Functions: cat ssh

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

plink -agent gist.github.com
nc -l $PORT | pv -b > archive.tar.bz2
2012-11-13 16:47:45
Tags: netcat tar pv

Receives bzip'd tar archive via netcat (openbsd nc) and stores locally. Displays size with pv. Start this receiver first, then the sender.

find $(YourPATH) -type f -exec dos2unix '{}' \;
make --print-data-base --dry-run | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
ping -c 3 google.com
gethostip -x
iozone -s 2g -r 64 -i 0 -i 1 -t 1
2009-11-19 10:43:54
User: w00binda

Iozone with a file of 2GB, 64KB record size, write/rewrite and read/re-read test, using just one thread.

find . -type f -not -regex ".*\/.svn\/.*" -exec sed -i 's/oldstring/newstring/g' {} +
grep -UIlr "^M" *
2010-08-20 21:16:34
User: randy909
Functions: grep

Where ^M is entered by ctrl-v-m (v then m). Especially useful on cygwin when checking into a version control system. If you're not using all cygwin tools (e.g. strawberry perl instead of cygwin perl) you'll find yourself dealing with this constantly.

-U tells grep to process the file as binary; it needs this to work

-I ignores binary files so you won't get false positives

-l only prints the filename instead of the offending lines

-r recursive

ls /var/log/ |wc -l
http_proxy=<proxy.server:port> wget <url>
2011-03-30 13:06:19
User: rdc
Functions: wget

On a machine behind a firewall, it's possible to pass the proxy server address in as a prefix to wget to avoid having to set it as an environment variable first.

perl -e "binmode(STDOUT, ':utf8'); print \"$@\""; echo # newline
2012-01-02 10:34:51
User: mathias
Functions: echo perl

This is especially useful to get crazy stuff like space characters copied to your pasteboard correctly.

Source: https://github.com/mathiasbynens/dotfiles/blob/master/.functions

sayspeed() { for i in $(seq 1 `echo "$1"|wc -c`); do echo -n "`echo $1 |cut -c ${i}`"; sleep 0.1s; done; echo "";}
2012-02-11 05:51:42
User: kundan
Functions: echo seq sleep wc

change the time that you would like to have as print interval

and just use it to say whatever you want to

pdftk 1.pdf 2.pdf cat output 12.pdf
git checkout HEAD~2 -- /path/to/dir