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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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,420 results
file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3
2009-09-03 14:28:02
Functions: cut file grep nl tail

Next time you see a mac fanboy bragging about 64-bitness of 10.6 give him this so he might sh?

O=$IFS;IFS=$'\n'; D=$(for f in *;do [[ -d $f ]] && du -sh "$f";done | sort -gr);F=$(for f in *;do [[ -f $f ]] && du -sh "$f";done | sort -gr);IFS=$O;echo "$D";echo "$F"
2009-09-03 11:39:50
User: Viperlin
Functions: du sort

biggest->small directories, then biggest->smallest files

echo sortmeplease|sed 's/./&\n/g'|sort|tr -d '\n'
ls -lct /etc | tail -1 | awk '{print $6, $7}'
2009-09-03 10:26:37
User: MrMerry
Functions: awk ls tail

Show time and date when you installed your OS.

echo sortmeplease | awk '{l=split($1,a,"");asort(a);while(x<=l){printf "%s",a[x];x++ }print "";}'
2009-09-03 10:22:39
User: foob4r
Functions: awk echo

using awk

missed the last char thanks @Josay

echo {1..199}" sheep," | espeak -v english -s 80
2009-09-03 10:08:12
User: MrMerry
Functions: echo

Can change language and speed, see espeak man page for options. (Install espeak in your linux distro via yum or apt-get)

For insomniacs you may need to enclose in a while true; do ...; done loop ;)

dd bs=1 seek=2TB if=/dev/null of=ext3.test
ls -shF --color
2009-09-03 05:45:33
User: Viperlin
Functions: ls

use manpages, they give you "ultimate commands"

"ls -SshF --color" list by filesize (biggest at the top)

"ls -SshFr --color" list by filesize in reverse order (biggest at the bottom)

sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
2009-09-03 04:40:10
User: kulor
Functions: sudo

adding users to groups on OS X is not a straightforward process, you need to use the new in built in Directory Service command line utility...

echo sortmeplease | grep -o . | sort | tr -d '\n'; echo
2009-09-03 00:52:49
User: MrMerry
Functions: echo grep sort tr

Sorts a character string, using common shell commands.

echo "5 k 3 5 / p" | dc
2009-09-03 00:21:54
User: xamaco
Functions: echo

using bc is for sissies. dc is much better :-D

Polish notation will rule the world...

find ~/Library/Application\ Support/Firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
nmap -R -sL | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
2009-09-02 16:33:15
User: netsaint
Functions: awk grep
Tags: nmap dns

This command uses nmap to perform reverse DNS lookups on a subnet. It produces a list of IP addresses with the corresponding PTR record for a given subnet. You can enter the subnet in CDIR notation (i.e. /24 for a Class C)). You could add "--dns-servers x.x.x.x" after the "-sL" if you need the lookups to be performed on a specific DNS server.

On some installations nmap needs sudo I believe. Also I hope awk is standard on most distros.

bc -l <<< s(3/5)
2009-09-02 15:41:39
User: akg240
Functions: bc

-l auto-selects many more digits (but you can round/truncate in your head, right) plus it loads a few math functions like sin().

awk '/d.[0-9]/{print $4}' /proc/partitions
2009-09-02 15:26:03
User: akg240
Functions: awk

Only one command and not dependant on full read access to the devices.

fdisk -l |grep -e '^/' |awk '{print $1}'|sed -e "s|/dev/||g"
cal -y
2009-09-02 12:57:23
User: andrepuel
Functions: cal

Show today date on a yearly calendar.

free -m | awk '/Swap/ {print $4}'
2009-09-02 11:46:17
User: voyeg3r
Functions: awk free

simple way to show free swap

free -b | grep "Swap:" | sed 's/ * / /g' | cut -d ' ' -f2
$php_dir/bin/php -i | grep configure
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
for dnsREC in $(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "$dnsREC " && dig +short $dnsREC IANA.ORG; done
sudo grub-install --recheck /dev/sda1
grep -lir "sometext" * > sometext_found_in.log
2009-08-31 23:48:45
User: shaiss
Functions: grep
Tags: find text

I find this format easier to read if your going through lots of files. This way you can open the file in any editor and easily review the file

cut -f N- file.dat