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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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





Commands using echo from sorted by
Terminal - Commands using echo - 1,303 results
echo "$(( $(( $(grep 'physical id' '/proc/cpuinfo' | uniq | wc -l) * $(grep 'core id' '/proc/cpuinfo' | wc -l) )) * 2 + 1 ))"
2015-11-14 20:44:39
User: snorf
Functions: echo
Tags: uniq

shell order of operation example which calculates:

x = number of physical CPU's

y = number of cores per CPU

2(x * y) + 1 = CPU load limit

echo "Gold price is" $(wget https://rate-exchange-1.appspot.com/currency\?from=XAU\&to=USD -q -O - | jq ".rate") "USD"
2015-11-11 14:20:06
User: lordtoran
Functions: echo wget
Tags: wget finance jq

Returns the current price of a troy ounce of gold, in USD. Requires the "jq" JSON parser.

echo 'echo /etc/games/fortune > ~/mailsignature.txt' >> .bashrc
2015-11-07 15:17:12
User: dededede
Functions: echo

In Thunderbird open the settings for your email account, mark the checkbox for 'Attach the signature from a file instead' and use the filename '~/mailsignature.txt'

Now every time when you open a terminal you see the fortune displayed in the terminal and the mail signature gets regenerated.

echo ${IP} | sed "s/[0-9\.]//g"
2015-10-19 18:20:03
User: andregyn62
Functions: echo sed

This command validates if exist any character different in 0-255 and dot.

If any characters different is typed the error menssage is showing.

echo $IP | egrep '^(([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$'
echo "obase=2;$((($(date +%s)-$(date +%s -d YYYY-MM-DD))/86400))" | bc
2015-10-19 15:40:32
User: flatcap
Functions: echo

Print out your age in days in binary.

Today's my binary birthday, I'm 2^14 days old :-)


This command does bash arithmatic $(( )) on two dates:

Today: $(date +%s)

Date of birth: $(date +%s -d YYYY-MM-DD)

The dates are expressed as the number of seconds since the Unix epoch (Jan 1970),

so we devide the difference by 86400 (seconds per day).


Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary.

(obase == output base)

echo "BTC rate is" $(wget https://api.bitcoinaverage.com/ticker/global/EUR/ -q -O - | jq ".last") "?"
2015-09-28 23:03:59
User: lordtoran
Functions: echo wget
Tags: wget bitcoin jq btc

Returns the global weighted BTC rate in EUR. Requires the "jq" JSON parser.

while true; do (echo -n $(date +"%F %T"):\ ; xwininfo -id $(xprop -root|grep "ACTIVE_WINDOW("|cut -d\ -f 5) | grep "Window id" | cut -d\" -f 2 ) >> logfile; sleep 60; done
2015-09-23 23:00:14
User: BeniBela
Functions: cut date echo grep sleep

This logs the titles of the active windows, thus you can monitor what you have done during which times. (it is not hard to also log the executable name, but then it is gets too long)

echo apt-get\ {update,-y\ upgrade}\ \&\& true | sudo bash
2015-09-22 00:48:26
User: alecthegeek
Functions: echo sudo true

it's nice to be able to use the command `ls program.{h,c,cpp}`. This expands to `ls program.h program.c program.cpp`. Note: This is a text expansion, not a shell wildcard type expansion that looks at matching file names to calculate the expansion. More details at http://www.linuxjournal.com/content/bash-brace-expansion

I often run multiple commands (like apt-get) one after the other with different subcommands. Just for fun this wraps the whole thing into a single line that uses brace expansion.

[ $(date +"%H") -lt 7 ] && echo you should probably be sleeping...
btc() { echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/$1.json | jq .bpi.\"$1\".rate | tr -d \"\"\") $1"; }
2015-09-19 02:49:30
User: benjabean1
Functions: echo

The only pre-requisite is jq (and curl, obviously).

The other version used grep, but jq is much more suited to JSON parsing than that.

echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/usd.json | grep -o 'rate":"[^"]*' | cut -d\" -f3) USD"
echo "quit" | openssl s_client -connect facebook.com:443 | openssl x509 -noout -text | grep "DNS:" | perl -pe "s/(, )?DNS:/\n/g"
ran() { R=$((RANDOM%100)); if [ $R -gt "${1:-50}" ]; then echo FALSE; false; else echo TRUE; true; fi; }
2015-07-15 15:34:56
User: snipertyler
Functions: echo

Command will succeed n% of the time.

ran 75 will cause command to succeed 75% of the time.

No argument will cause it to succeed 50% of the time.

echo "text to prepend" | cat - file
for file in $( git ls-files ); do echo $file; touch -t $(git --no-pager log --date=local -1 --format="%ct" $file | php -r 'echo @date( "YmdHi.s", trim( file_get_contents( "php://stdin" ) ) );') $file; done
echo "display:data?" | nc "$scope_ip_address" 5555 | dd bs=1 skip=11 2>/dev/null | convert bmp:- out_file.png
2015-06-27 06:43:43
User: ichbins
Functions: dd echo
Tags: convert rigol

Scope should have the Rigol Ultravision Technology otherwise it won't accept the command. ImageMagic is required. Scope sends a 1.1M BMP file and converted to PNG it's only 18-20K

for x in {a..d}; do echo -e "n\np\n\n\n\nt\n8e\nw\n" | fdisk /dev/sd"$x"; done
2015-05-21 12:59:48
User: jaimerosario
Functions: echo fdisk
Tags: fdisk for loop

So, I'm using a CentOS VM in VirtualBox, and created four new disks in the SCSI controller.

The VM created the folders:





Using a 'for loop' all disks are partitioned for LVM.

for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='\0' -F= '$1=="DISPLAY" {print $2}' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d
2015-05-18 20:01:20
User: geyslan
Functions: awk cat echo
Tags: display xorg

It's useful when you cannot access your env (systemd) or the process DISPLAY variable is not set. Perhaps also when you have a multi-head/user configuration.

fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
2015-05-11 16:46:01
User: nnsense
Functions: basename echo grep rpm whatis

Many times I give the same commands in loop to find informations about a file. I use this as an alias to summarize that informations in a single command. Now with variables! :D

echo FileName | perl -nlE'sleep 1 while time-(stat)[10]<10' && echo DONE
2015-05-09 14:58:41
User: pung96
Functions: echo perl

perl version of "Wait for file to stop changing"

When "FileName" has not been changed for last 10 seconds, then print "DONE"

"10" in "(stat)[10]" means ctime.

One have other options like atime, mtime and others. http://perldoc.perl.org/functions/stat.html

while [ $(( $(date +%s) - $(stat -c %Y FILENAME) )) -lt 10 ]; do sleep 1; done; echo DONE
2015-05-09 12:30:13
User: flatcap
Functions: date echo sleep stat

This loop will finish if a file hasn't changed in the last 10 seconds.


It checks the file's modification timestamp against the clock.

If 10 seconds have elapsed without any change to the file, then the loop ends.


This script will give a false positive if there's a 10 second delay between updates,

e.g. due to network congestion


How does it work?

'date +%s' gives the current time in seconds

'stat -c %Y' gives the file's last modification time in seconds

'$(( ))' is bash's way of doing maths

'[ X -lt 10 ]' tests the result is Less Than 10

otherwise sleep for 1 second and repeat


Note: Clever as this script is, inotify is smarter.

echo $(date +%m) past $(date +%H) | espeak
2015-05-09 12:24:13
User: hal8
Functions: date echo

s/espeak/say/ on a mac

echo -e $_{1..80}'\b+'
while kill -0 0; do timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for _ in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'; done
2015-05-07 19:13:08
User: anapsix
Functions: bash echo kill seq sleep

alternatively, run the spinner for 5 seconds:

timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for j in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'