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



Commands using echo from sorted by
Terminal - Commands using echo - 1,330 results
export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
2009-10-23 07:47:11
User: m33600
Functions: date echo export printf watch

Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small.

Try changing fonts and sizes of osd_cat

export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
2009-10-23 07:31:44
User: m33600
Functions: date echo export printf watch

Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch

Shows elapsed time from start of script in hh:mm:ss format

Non afected by system slow down due to the use of date.

pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null
2009-10-22 12:32:11
User: syladmin
Functions: cd echo ls sed
Tags: permissions

Can easily be scripted in order to show permission "tree" from any folder. Can also be formated with

column -t

{ pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null ; } | column -t

from http://www.commandlinefu.com/commands/view/3731/using-column-to-format-a-directory-listing

echo $(shuf -i 1-49 | head -n6 | sort -n)
seg() { for b in $(echo $1); do for x in $(seq 10); do echo $b.$x; done; done }
seg() { echo -e "$1" | while read LINE; do for b in $(seq 10); do echo $LINE.$b; done; done; }
echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk /dev/sdX
2009-10-20 16:21:54
User: sud0er
Functions: echo fdisk
Tags: Linux fdisk

This is a bit hacky, but if you're setting up a bunch of new LUNs, it can save a bunch of time. Also check out sfdisk. The fdisk will fail if, for example, a partition table already exists.

for a in bzip2 lzma gzip;do echo -n>$a;for b in $(seq 0 256);do dd if=/dev/zero of=$b.zero bs=$b count=1;c=$(date +%s%N);$a $b.zero;d=$(date +%s%N);total=$(echo $d-$c|bc);echo $total>>$a;rm $b.zero *.bz2 *.lzma *.gz;done;done
2009-10-20 01:00:51
User: matthewbauer
Functions: bzip2 date dd echo seq

See: http://imgur.com/JgjK2.png for example.

Do some serious benchmarking from the commandline. This will write to a file with the time it took to compress n bytes to the file (increasing by 1).


gnuplot -persist <(echo "plot 'lzma' with lines, 'gzip' with lines, 'bzip2' with lines")

To see it in graph form.

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.

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

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

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...

echo "" > .bash_history
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
seq 10 |xargs -n1 echo Printing line
2009-10-15 11:05:35
User: Waldirio
Functions: echo seq xargs
Tags: echo xargs seq

Nice command to create a list, you can create too with for command, but this is so faster.

n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
ping -q -c1 -w3 brandx.jp.sme 2&>1 /dev/null || echo brandx.jp.sme ping failed | mail -ne -s'Server unavailable' [email protected]
2009-10-13 14:13:04
User: mccalni
Functions: echo mail ping
Tags: bash ping mail

Joker wants an email if the Brand X server is down. Set a cron job for every 5 mins with this line and he gets an email when/if a ping takes longer than 3 seconds.

echo $RANDOM$RANDOM$RANDOM |cut -c3-12
dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done
2009-10-12 14:57:54
User: pykler
Functions: bash cut du echo read sed tail tr xargs
Tags: Debian wajig

Calculates the size on disk for each package installed on the filesystem (or removed but not purged). This is missing the

| sort -rn

which would put the biggest packges on top. That was purposely left out as the command is slightly on the slow side

Also you may need to run this as root as some files can only be checked by du if you can read them ;)

b="http://2010.utosc.com"; for p in $( curl -s $b/presentation/schedule/ | grep /presentation/[0-9]*/ | cut -d"\"" -f2 ); do f=$(curl -s $b$p | grep "/static/slides/" | cut -d"\"" -f4); if [ -n "$f" ]; then echo $b$f; curl -O $b$f; fi done
2009-10-11 17:28:46
User: danlangford
Functions: cut echo grep
Tags: curl cut for UTOSC

miss a class at UTOSC2010? need a refresher? use this to curl down all the presentations from the UTOSC website. (http://2010.utosc.com) NOTE/WARNING this will dump them in the current directory and there are around 37 and some are big - tested on OSX10.6.1

ifs () { echo -n "${IFS}"|hexdump -e '"" 10/1 "'\''%_c'\''\t" "\n"' -e '"" 10/1 "0x%02x\t" "\n\n"'|sed "s/''\|\t0x[^0-9]//g; $,/^$/d"
2009-10-10 22:41:35
User: dennisw
Functions: echo hexdump sed

You can display, save and restore the value of $IFS using conventional Bash commands, but these functions, which you can add to your ~/.bashrc file make it really easy.

To display $IFS use the function ifs shown above. In the sample output, you can see that it displays the characters and their hexadecimal equivalent.

This function saves it in a variable called $saveIFS:

sifs () { saveIFS=$IFS; }

Use this function to restore it

rifs () { IFS=$saveIFS; }

Add this line in your ~/.bashrc file to save a readonly copy of $IFS:

declare -r roIFS=$IFS

Use this function to restore that one to $IFS

rrifs () { IFS=$roIFS; }
head -c10 <(echo $RANDOM$RANDOM$RANDOM)
2009-10-09 15:09:02
User: jgc
Functions: echo head
Tags: HEAD random

Makes use of $RANDOM environment variable.

if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
2009-10-09 14:57:27
User: jgc
Functions: echo

Using the standard numeric comparison but suppressing the STDERR output acts as the simplest way to check a value is numeric. See sample output for some examples.

echo $X | egrep "^[0-9]+$"