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
dd if=/dev/disk1 of=disk1.iso
2012-02-06 13:58:15
User: DevEd
Functions: dd

This command dumps a mounted disk to an ISO image. (Use "mount" to get the mounted disk's name.)

Make sure to un-mount the disk first.

wget -qO - http://whatismyip.org | tail
2012-03-17 10:13:05
User: Flolagale
Functions: wget

Uses wget standard GNU utility. Prints only your ip.

export MYSQL_PS1="mysql://\u@\h:/\d - \R:\m:\s > "
2012-11-03 18:22:16
User: Testuser_01
Functions: export

You can put this into your shell sourced file like .bashrc or .zshrc to have a different mysql prompt.

See http://dev.mysql.com/doc/refman/5.1/de/mysql-commands.html for more informations.

Beware that currently with mysql 5.5 the seconds are buggy and won't be displayed if you put this into a .cnf file. With the enironment variable this will work.

ls -l | grep ^d
openssl dgst -md5 file.ext
netstat -np --inet|awk '/firefox/{split($5,a,":");z[a[1]]++} END{for(i in z){system("whois " i)}}'|less
wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'
2014-03-15 02:04:08
User: lowjax
Functions: get grep

Using "wmic get * /value" within any Cygwin shell will return lots of Win/Dos newline junk ie "^M$" at the end of found value line, two lines ("$" Unix newline) above, and three below. This makes storing and or evaluating wmic queries as variables a pain. The method i suggest strips the mentioned junk, only returns the value after "OSArchitecture=", and includes only one Unix style newline. Other methods using sed|awk|cut can only handle the output of wmic cleanly when piped or using multiple sed statements.

wmic OS get OSArchitecture /value | sed 's/\r//g;s/^M$//;/^$/d;s/.*=//'


wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'

a much cleaner and slightly less costly alternative.

grep "btrfs: checksum error at logical" /var/log/messages | egrep -o "[^ ]+$" | tr -d ')' | sort | uniq
2014-07-01 08:15:26
User: jcoll
Functions: egrep grep sort tr

Filter entries in OpenSuse /var/log/messages like:

timestamp servername kernel: [83242.108090] btrfs: checksum error at logical 1592344576 on dev /dev/sda5, sector 5223584, root 5, inode 2652, offset 282624, length 4096, links 1 (path: log/warn)

psg() { if [ -z "$2" ]; then psargs="aux"; greparg="$1"; else psargs="$1"; greparg="$2"; fi; ps $psargs | grep -i "$(echo $greparg | sed -e 's/^\(.\)/[\1]/')\|^$(ps $psargs | head -1)" ; }
2009-02-18 20:57:17
User: DEinspanjer
Functions: grep ps

My variant on this common function. Some highlights:

Allows you to override the default ps args of "aux"

Uses bracket trick to omit the grep process itself without having to use a second grep

Always prints the correct header row of ps output

Limitations: Ugly ps error output if you forget to quote your multi word grep argument

fetchmail -p etrn --fetchdomains yourdomain.example.org secondary-server.example.org
2010-11-20 23:38:09
User: jasonjgw
Functions: fetchmail

This uses fetchmail to issue an etrn command that causes the MTA on the secondary mail server to process the queue for the specified domain.

You can also just use telnet or nc to connect to port 25 of the server and then:

etrn yourdomain.example.org

250 2.0.0 Queuing for node yourdomain.example.org started

grep -l foo *cl*.log | xargs grep -lL bar
2011-01-10 20:18:30
User: dlebauer
Functions: grep xargs
Tags: xargs grep

same as

grep -lL "foo" $(grep -l bar *cl*.log)
defaults write com.apple.terminal FocusFollowsMouse -string YES
2011-07-26 02:15:04
User: ratonovitch
Functions: write

In Mac OS X, by default, you have to click the mouse on a Terminal window before you can type in it. You can change this behavior to mimic the X11 behavior of focusing on the window on mouseover.

curl http://my-ip.cc/host.json
2011-09-01 00:31:49
User: samleb

JSON version.

Additionally it may give your geolocation if it's known by hostip.info

stat --format "%s" <file>
mysql -u root -p -N -e"show processlist\G;" | egrep "Host\:" | awk -F: '{ print $2 }' | sort | uniq -c
outlook.exe /cleanreminders
2012-02-06 14:11:45
User: 0verlord

In case of mailbox recovery and duplicated task/appointment reminders afterwards.

if [ -n "$SSH_CONNECTION" ]; then export TMOUT=300; fi
2012-11-03 18:39:25
User: Testuser_01
Functions: export

This will check if a user is logged in using ssh and will log out the user automatically after the specified time in seconds without data retrieval on the server side.

Will work with bash and zsh so put it into your sourced shell file on the server side.

Be aware that users can change this themselves as it's just a envoronment variable.

echo "btrfs checksum error(s) on: " && grep "btrfs: checksum error at logical" /var/log/messages | sed -e 's/^.*\( dev .*\)\(, sector.*\)\(path\: .*\))/\t\1, \3/' | sort | uniq
clear; for i in `cat thehosts` ; do ssh $i "cat uname -a ; /etc/redhat-release; cat /proc/cpuinfo | tail -n 25 | egrep '^processor|^model name' "; free ; df -h ;done
fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g"
curl -s -c /tmp/cookie -k -u tivo:$MAK --digest http://$tivo/download/$filename | tivodecode -m $MAK -- - | mplayer - -cache-min 50 -cache 65536
find . -name '*.xml' -type f -print | xargs du -ch
2011-03-22 00:47:42
User: nathwill
Functions: du find xargs
Tags: find du type

print sum of disk usage for filetype within current dir and subdirs

rm -- -i
2011-07-26 04:00:32
User: merlinblack
Functions: rm

If you just try rm -i, the file name will be interpreted as a command line switch. Many commands let you use a double hyphen '--' to say 'No more switches, the rest are file names'.

Incidentally having a file named '-i' in a directory where you use rm * will cause rm to act as if you specified '-i' on the command line.

vim -- -v touch -- -t cat -- -c
svn log -r{2011-08-01}:HEAD|awk '$14 ~/line/ {print $3}'|sort|uniq -c
2011-09-01 07:58:54
User: sangnoir
Functions: awk uniq

My script lists all users & the number of commits they made in the period, sorted alphabetically. To sort by number of commits, append a '|sort' to the end of the command. The script depends on the output format of svn log - original command didn't work for me because the string 'user' was not appearing in my output