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,332 results
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]+$"
for USER in `ls /var/spool/cron`; do echo "=== crontab for $USER ==="; echo $USER; done
tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
2009-10-08 16:48:04
User: jgc
Functions: echo sleep tput

Very useful for interactive scripts where you would like to return the terminal contents to its original state before the script was run. This would be similar to how vi exits and returns you to your original terminal screen.

Save and clear the terminal contents with:

tput smcup

Execute some commands, then restore the saved terminal contents with:

tput rmcup
for USER in `cut -d ":" -f1 </etc/passwd`; do crontab -u ${USER} -l 1>/dev/null 2>&1; if [ ! ${?} -ne 0 ]; then echo -en "--- crontab for ${USER} ---\n$(crontab -u ${USER} -l)\n"; fi; done
2009-10-07 20:51:01
User: tharant
Functions: crontab echo

This is how I list the crontab for all the users on a given system that actually have a crontab.

You could wrap it with a function block and place it in your .profile or .bashrc for quick access.

There's prolly a simpler way to do this. Discuss.

echo "vertical text" | fold -1
sitepass() { echo -n "[email protected]" | md5sum | sha1sum | sha224sum | sha256sum | sha384sum | sha512sum | gzip - | strings -n 1 | tr -d "[:space:]" | tr -s '[:print:]' | tr '!-~' 'P-~!-O' | rev | cut -b 2-11; history -d $(($HISTCMD-1)); }
2009-10-01 20:14:57
User: syssyphus
Tags: Security

usage: sitepass MaStErPaSsWoRd example.com

description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history.

tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy

rev # this avoids the first few bytes of gzip payload, and the magic bytes.

echo $(</tmp/foo)
expdp user/password FLASHBACK_SCN=$(echo -e "select current_scn from v\$database;" | sqlplus / as sysdba 2>/dev/null| grep [0-9][0-9][0-9][0-9][0-9][0-9]*)
2009-10-01 08:55:20
User: peshay
Functions: as echo grep

Creates a consistent datapumpt export on an Oracle database with the current sequence number, while the system is running and changes happens on the database.

check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenavnbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "available" ; fi ; sleep 1 ;done }
2009-09-30 21:17:33
User: xeor
Functions: echo grep sleep
Tags: wget dig dns

Mostly for Norwegians, but easily adoptable to others. Very handy if you are brainstorming for a new domainname.

Will only display the available ones..

You can usually do this better with dig, but if you dont have dig, or the TLD only have an online service to check with, this will be usefull..

(crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
2009-09-30 18:13:38
User: syssyphus
Functions: crontab dmesg echo

this is helpful because dmesg is where i/o errors, etc are logged to... you will also be able to see when the system reboots or someone attaches a thumb drive, etc.

don't forget to set yourself up in /etc/aliases to get roots email.

echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
s=124890; array=($(echo $s | sed 's/./& /g')); echo ${array[@]}; echo ${!array[@]}
2009-09-29 12:30:04
User: tatsu
Functions: echo sed

Convert string to array using echo and sed =)

[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month'
PERMA () { echo "[email protected]" >> ~/.bashrc; }
2009-09-28 16:03:24
User: zlemini
Functions: echo

Simple function to permanently add an alias to your profile.

Tested on bash and Ksh, bash version above.

Here is the ksh version: PERMA () { print "[email protected]" >> ~/.profile; }

Sample usage:

PERMA alias la='ls -a'

echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
2009-09-27 15:30:38
User: dennisw
Functions: echo
Tags: color

I like the fact the Patola's version uses only ones and zeros, but I also like the sparse output of the other versions. This one combines both of those features and eliminates some unnecessary cruft.

You can vary the sparseness by changing "$(($RANDOM % 5))" to another number. The number in this term "$(($RANDOM % 4))" controls how frequently the numbers are output bold.

echo "blacklist pcspkr"|sudo tee -a /etc/modprobe.d/blacklist.conf
2009-09-27 11:42:47
User: sliceoflinux
Functions: echo sudo tee

This command will disable the beep sound from the PC speaker.

beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
2009-09-24 18:11:10
Functions: echo host ping read seq
Tags: ping beep

After this, just type:


You need to install "beep" before this would make the beep sound.

Save it in your .profile if you want to use it later

WARNING: this command won't exit until it is successful. You won't be able to CONTROL+C out of it.

echo $PATH|tr : '\n'|sort|uniq -d
host A: cat /proc/dev/ttyS0 host B: echo hello > /dev/ttyS0
2009-09-24 13:22:23
User: flart
Functions: cat echo host

If the connection works you should see a "hello" on host A. If not: check your cabeling etc :-)

mplayer -vo dummy -ao dummy -identify * 2>&1 | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | xargs echo | sed 's/ /+/g' | bc | awk 'S=$1; {printf "%dh:%dm:%ds\n",S/(60*60),S%(60*60)/60,S%60}'
2009-09-24 10:33:19
User: Strawp
Functions: awk bc echo grep sed xargs

You're behind on your TV catch-up, but how far behind? This command tries to open mplayer against all files in the current dir. If it's a video file it will contain ID_LENGTH, which is summed and output in hours, minutes and seconds.

Someone better at awk could probably reduce this down a lot.

(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
for each in `cut -d " " -f 1 inputfile.txt`; do echo "select * from table where id = \"$each\";"; done
2009-09-23 13:29:16
User: hfs
Functions: echo
Tags: echo cut for-each

I never can remember the syntax of awk. You can give a different -d option to cut to separate by e.g. commas. Also this allows to do more things with the generated SQL, e.g. to redirect it into different files.

echo 'Enter Picasa album RSS URL:"; read -e feedurl; GET "$feedurl" |sed 's/</\n</g' | grep media:content |sed 's/.*url='"'"'\([^'"'"']*\)'"'"'.*$/\1/' > wgetlist
2009-09-22 10:51:08
User: kamathln
Functions: echo

Grab the RSS link to the Picasa album. Feed it to the script when its hungry. When its done writing the shopping list, just use

wget -c -i wgetlist

to get your stuff.

echo "see attached file" | mail -a filename -s "subject" [email protected]
2009-09-21 11:58:49
User: gnpf
Functions: echo mail
Tags: mail

if "mail -a" fail, try "mutt -a" or "nail -a"