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,430 results
echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
2009-10-19 05:28:15
User: m33600
Functions: acpi echo watch

This time I added a print to reemaining energy, every minute, time stamped.

The example shown here is complete and point to large discrepancies as time passes, converging to accuracy near the end.

for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
2009-10-18 20:41:47
Functions: awk cut grep netstat

Sample command to obtain a list of geographic localization for established connections, extracted from netstat. Need geoiplookup command ( part of geoip package under CentOS)

echo start > battery.txt; watch -n 60 'date >> battery.txt'
2009-10-18 07:00:26
User: m33600
Functions: echo watch

Fully recharge your computer battery and start this script.

It will create or clean the file named battery.txt, print a start on it and every minute it will append a time stamp to it.

Batteries last few hours, and each hour will have 60 lines of time stamping. Really good for assuring the system was tested in real life with no surprises.

The last time stamp inside the battery.txt file is of interest. It is the time the computer went off, as the battery was dead!

Turn on your computer after that, on AC power of course, and open battery.txt. Read the first and last time stamps and now you really know if you can trust your computer sensors.

If you want a simple line of text inside the battery.txt file, use this:

watch -n 60 'date > battery.txt'

The time of death will be printed inside

weather() { lynx -dump "http://mobile.weather.gov/port_zh.php?inputstring=$*" | sed 's/^ *//;/ror has occ/q;2h;/__/!{x;s/\n.*//;x;H;d};x;s/\n/ -- /;q';}
ord() { printf "%d\n" "'$1"; }
2009-10-17 22:02:52
User: zude
Functions: printf

printf treats first char after single ' as numeric equivalent

for file in *.iso; do mkdir `basename $file | awk -F. '{print $1}'`; sudo mount -t iso9660 -o loop $file `basename $file | awk -F. '{print $1}'`; done
time dd if=/dev/zero of=TEST bs=4k count=512000
mkisofs -o XYZ.iso XYZ/
2009-10-17 16:28:47
User: eastwind
Functions: mkisofs

create iso image from directory . Usefull for virtualised machine

To create CD ISO image of directories that contain long file name or non-8.3 format (particularly if you want to burn the CD image for use in Windows system), use the -J option switch that generates Joliet directory records in addition to regular iso9660 file names. For example, to create CD image of Vista SP1 directory: mkisofs -o VitaSP1.iso -J VistaSP1

echo -n a | od -d | sed -n "s/^.* //gp"
2009-10-17 15:46:00
User: stf42
Functions: echo od sed

the shortest command for character 'a' i know

x=1 ; while [ $x -le 10 ] ; do lynx -dump http://www.alexa.com/siteinfo/http://[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done &
2009-10-17 13:48:05
User: felix001
Functions: grep sed sleep

This will record the Alexa Traffic Stats to a file and run every 5 hours.

-- www.fir3net.com --

printf "%d\n" "'A" "'B"
chr () { echo -en "\0$(printf %x $1)"}
ord () { seq 1 127 | while read i; do echo `chr $i` $i; done | grep "^$1 " | cut -c '3-' }
2009-10-16 21:54:01
User: infinull
Functions: cut echo grep read seq

uses the previous "chr" function and uses it to create the inverse function "ord" by brute force.

It's slow, It's inelegant, but it works.

I thought I needed ord/chr to do a cartesian cipher in shell script a whie ago, but eventualy I realized I could get fancy with tr and do the same thing...

chr() { printf \\$(printf %o $1); }
argv=("[email protected]"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
2009-10-16 17:36:16
User: lassel
Functions: less
Tags: bash less log grep

Really useful way to combine less and grep while browsing log files.

I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep:


lgrep searchfor file1 [file2 file3]

Advanced example (grep for an Exception in logfiles that starts with qc):

lgrep Exception $(find . -name "qc*.log")

history -c && rm -f ~/.bash_history
2009-10-16 13:48:20
Functions: rm

Note the space before the command; that prevents your history eliminating command from being recorded. ' history -c && rm -f ~/.bash_history' Both steps are needed. 'history -c' clears what you see in the history command. 'rm -f ~/.bash_history' deletes the history file in your home directory.

history -c
echo "" > .bash_history
perl -e '$i=0;while($i<10){open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http://www.google.com/search?q=site:g33kinfo.com&hl=en&start=$i&sa=N},$i+=10}'|grep '\/\/g33kinfo.com\/'
2009-10-16 12:20:17
User: op4
Functions: grep perl xargs
Tags: web browser

not my cmd... found on the web

HDD=$(df | awk ' NR>3 (S=$5) (M=$6) { if (S>90) print "Your Systems "M" is """S" Full" } ') ; [[ $HDD ]] && echo "$HDD" | mail -s "Hard-Drives Full" [email protected] -- -f [email protected] >/dev/null
tail -F file | egrep --color 'pattern|$'
gconftool -t str -s /desktop/gnome/background/picture_filename "`find /DIR_OF_JPGS -name '*.jpg' | shuf -n 1`"
2009-10-16 01:17:47
User: cbrinker

Every time this is run it will change your background picture. For added fun

Add some DBUS magic:

. $HOME/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0


and a crontab entry:

*/5 * * * * above_command_in_script.sh >/dev/null 2>/dev/null

now wallpaper changes every 5 mins

for i in ~/Desktop/Personal/Wallpapers/*.jpg ; { size=$((`identify -format "%wx%h" $i | sed 's/x/*/'`)) ; if [[ $size -lt 800001 ]] then ; rm -f "$i" ; fi; }
2009-10-16 00:21:21
User: cbrinker
Functions: rm sed

For all of the jpgs in a directory, determine their size and if below a threshold remove them forcefully.

mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac mp3lame -lameopts br=98 -o output.wmv input.mpg
[ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" [email protected]
2009-10-15 21:11:54
User: syssyphus
Functions: df perl

put it in crontab to get an alert when / is over 89% utilization.