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,378 results
cat /etc/passwd | openssl aes-256-cbc -a -e -pass pass:password | netcat -l -p 8080
2009-09-04 20:04:24
User: flip387
Functions: cat

Using OpenSSL we can encrypt any input we wish and then use Netcat to create a socket which can be connected to from an externally source (even using a Web Browser)

vimdiff <(svn cat "$1") "$1"
2009-09-04 18:41:40
User: plasticboy
Functions: cat
Tags: svn vim diff color

This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:

svd() { vimdiff <(svn cat "$1") "$1"; }
find . -name .svn -prune -o -print
2009-09-04 17:41:33
User: arcege
Functions: find
Tags: svn find

Put the positive clauses after the '-o' option.

svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
2009-09-04 17:23:45
User: arcege
Functions: sed sh
Tags: svn sed shell

Manages everything through one sed script instead of pipes of greps and awks. Quoting of shell variables is generally easier within a sed script.

badblocks -vfw /dev/fd0 10000 ; reboot
2009-09-04 16:57:51
User: SuperFly
Functions: badblocks

THIS COMMAND IS DESTRUCTIVE. That said, lets assume you want to render your boot drive unbootable and reboot your machine. Maybe you want it to boot off the network and kickstart from a boot server for a fresh OS install. Replace /dev/fd0 with the device name of your boot drive and this DESTRUCTIVE command will render your drive unbootable. Your BIOS boot priority should be set to boot from HD first, then LAN.

ssh -f -L3307: -N -t -x [email protected] sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=,P=3307 u=root,p=xxx,h=localhost
2009-09-04 16:54:25
Functions: sleep ssh

I wanted to keep a backup of my company database server on my local homeserver. After I found maatkit to sync databases, everything except security seemed fine. SSH takes care of that part.

ls -lct /etc/ | tail -1 | awk '{print $6, $7, $8}'
2009-09-04 16:52:50
User: peshay
Functions: awk ls tail

shows also time if its the same year or shows year if installed before actual year and also works if /etc is a link (mac os)

find . -type f -name '*.c' -exec wc -l {} \; | awk '{sum+=$1} END {print sum}'
2009-09-04 15:51:30
User: arcege
Functions: awk find wc
Tags: awk find wc

Have wc work on each file then add up the total with awk; get a 43% speed increase on RHEL over using "-exec cat|wc -l" and a 67% increase on my Ubuntu laptop (this is with 10MB of data in 767 files).

bc -l <<< "x=2; p=0.5; e(l(x)*p)"
watch -n <seconds> <command>
/sbin/badblocks -v /dev/fd0 1440
tcpdump -n -v tcp or udp or icmp and not port 22
du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done
2009-09-03 20:43:43
User: nickwe
Functions: cut du echo read sed sort

Based on the MrMerry one, just add some visuals to differentiate files and directories

2009-09-03 20:38:32
User: nickwe
Tags: du ncdu ncurses

An NCurses version of the famous old 'du' unix command

find . -maxdepth 1 -type d|xargs du -a --max-depth=0|sort -rn|cut -d/ -f2|sed '1d'|while read i;do echo "$(du -h --max-depth=0 "$i")/";done;find . -maxdepth 1 -type f|xargs du -a|sort -rn|cut -d/ -f2|sed '$d'|while read i;do du -h "$i";done
2009-09-03 20:33:21
User: nickwe
Functions: cut du echo find read sed sort xargs

Based on the MrMerry one, just add some visuals and sort directory and files

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

To highlight the difference between screen updates

watch 'cat /proc/loadavg'
2009-09-03 20:10:46
User: 0disse0
Functions: watch
Tags: status watch

If you need to keep an eye on a command whose output is changing, use the watch command. For example, to keep an eye on your load average

ioreg -l -p IODeviceTree | grep -o EFI[0-9]. && system_profiler SPSoftwareDataType |grep 64
gnome-terminal --tab --tab --tab
2009-09-03 19:36:07
User: 0disse0
Tags: terminal gnome

If you launch gnome-terminal manually, you can start with three open tabs

function checkfor () { while :; do $*; sleep 5; done; }
2009-09-03 19:35:42
User: relay
Functions: sleep
Tags: bash

checkfor: have the shell check anything you're waiting for.

'while : ; do' is an infinite loop

'$*' executes the command passed in

'sleep 5' - change for your tastes, sleep for 5 seconds

bash, ksh, likely sh, maybe zsh

Ctrl-c to break the loop

apt-key list
2009-09-03 19:32:11
User: 0disse0
Functions: apt
Tags: apt-key

For example: check the APT security keys to make sure the Google digital signature was imported correctly

apt-cache stats
man 5 crontab
2009-09-03 19:27:08
User: 0disse0
Functions: man

You can view the man pages from section five by passing the section number as an argument to the man command

function fcd () { [ -f $1 ] && { cd $(dirname $1); } || { cd $1 ; } pwd }
2009-09-03 18:58:13
User: relay
Functions: cd dirname pwd
Tags: bash ksh

fcd : file change directory

A bash function that takes a fully qualified file path and cd's into the directory where it lives. Useful on the commadline when you have a file name in a variable and you'd like to cd to the directory to RCS check it in or look at other files associated with it.

Will run on any ksh, bash, likely sh, maybe zsh.

find . -type f -exec grep -qi 'foo' {} \; -print0 | xargs -0 vim
2009-09-03 17:55:26
User: arcege
Functions: find grep xargs
Tags: vim find grep

Make sure that find does not touch anything other than regular files, and handles non-standard characters in filenames while passing to xargs.