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,291 results
echo "!!" > foo.sh
2009-02-25 00:37:25
User: dnavarre
Functions: echo

Sometimes commands are long, but useful, so it's helpful to be able to make them permanent without having to retype them. An alternative could use the history command, and a cut/sed line that works on your platform.

history -1 | cut -c 7- > foo.sh
declare -i aa ; aa=3*8 ; echo $aa
echo *.log | xargs <command>
2009-02-22 11:32:55
User: mikeda
Functions: echo xargs
grep ERROR *.log

-bash: /bin/grep: Argument list too long

echo *.log | xargs grep ERROR /dev/null

20090119.00011.log:DANGEROUS ERROR

read VAR1 VAR2 VAR3 < <(echo aa bb cc); echo $VAR2
echo -en "stats\r\n" "quit\r\n" | nc localhost 11211 | tr -s [:cntrl:] " "| cut -f42,48 -d" " | sed "s/\([0-9]*\)\s\([0-9]*\)/ \2\/\1*100/" | bc -l
doloop() { DONT=/tmp/do-run-run-run; while true; do touch $DONT; (sleep 30; rm $DONT;) & $1 ; if [ -e $DONT ]; then echo restarting too fast; return ; fi ; done }
2009-02-21 02:11:18
User: evil_otto
Functions: echo return rm sleep touch

This runs a command continuously, restarting it if it exits. Sort of a poor man's daemontools. Useful for running servers from the command line instead of inittab.

HOST=;for((port=1;port<=65535;++port)); do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null; then echo -en "\n\nport $port/tcp is open\n\n";fi;done | grep open
echo "hello world" | festival --tts
2009-02-20 14:00:50
Functions: echo

The Festival Speech Synthesis System converts text into sound.

Or: links -dump http://youfavoritewebsite.com | festival --tts

FLOOR=0; RANGE=10; number=0; while [ "$number" -le $FLOOR ]; do number=$RANDOM; let "number %= $RANGE"; done; echo $number
2009-02-20 09:33:56
User: raphink
Functions: echo
Tags: bash

This one-liner outputs a random number between the values given for FLOOR and RANGE.

/lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
2009-02-20 06:06:29
User: mrtheplague
Functions: c++ echo gcc

is the runtime linker/loader for ELF binaries on Linux.

=(cmd) is a zsh trick to take the output for the command "inside" it and save it to a temporary file.

echo -e 'blah' | gcc -x c -o /dev/stdout -

pipes the C source to gcc. -x c tells gcc that it's compiling C (which is required if it's reading from a pipe). -o /dev/stdout - tells it to write the binary to standard output and read the source from standard input.

because of the the =() thing, the compiled output is stashed in a tempfile, which the loader then runs and executes, and the shell tosses the tempfile away immediately after running it.

echo 1 > /proc/sys/kernel/sysrq; echo b > /proc/sysrq-trigger
2009-02-20 00:37:18
User: tsaavik
Functions: echo

This will cause your machine to INSTANTLY reboot. No un-mounting of drives or anything.

Very handy when something has gone horribly wrong with your server in that co-location facility miles away with no remote hands!

Suspect this works with all 2.2, 2.4 and 2.6 Linux kernels compiled with magic-syskey-request support.

for i in `recode -l | cut -d" " -f 1`; do echo $i": ?" | recode utf-8..$i -s -p >> temp; done; vim temp
2009-02-20 00:14:33
User: saerdnaer
Functions: cut echo vim

If you have some textfile with an unknown encoding you can use this list to find out

check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
while [ 0 ]; do echo -e "HTTP/1.1 302 Found\nLocation: http://www.whatevs.com/index.html" | nc -vvvv -l -p 80; done
2009-02-19 18:04:01
User: wwest4
Functions: echo

any HTTP requests to the machine on the specified port will be redirected to http://www.whatevs.com... quick, dirty, works fine for sites w/

echo "8000000/(20*6*86400)" | bc -l
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"
2009-02-19 14:15:31
User: stinger
Functions: echo

above line in .bash_profile will give you window title in putty or terminal client when you login to your remote server

echo 1+1|bc
while true; do read i; echo $[$i]; done
2009-02-18 23:13:09
User: mulad
Functions: echo read

The $[...] block in bash and zsh will let you do math.

echo $[6*7]

This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.

for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
2009-02-18 20:31:46
User: mestr
Functions: echo sleep

Countdown from 10 or whatever you want:)

unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

echo "foo bar" | sudo tee -a /path/to/some/file
2009-02-18 13:54:25
User: raphink
Functions: echo sudo tee

This is the solution to the common mistake made by sudo newbies, since

sudo echo "foo bar" >> /path/to/some/file

does NOT add to the file as root.


sudo echo "foo bar" > /path/to/some/file

should be replaced by

echo "foo bar" | sudo tee /path/to/some/file

And you can add a >/dev/null in the end if you're not interested in the tee stdout :

echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
echo "^[]0;My_Title_Goes _Here^G"
2009-02-17 20:46:06
User: TheNomad
Functions: echo

If you are using an xterm emulation capable terminal emulator, such as PuTTY or xterm on Linux desktop, this command will replace the title of that terminal window. I know it is not nice to have seventeen terminals on your desktop with title PuTTY, you can not tell which one is connected to which server and doing what.

Even though the string between the quotes is typed as literals, it needs a little more finesse to make it work. Here is how it is done key-by-key:

echo "( ctrl-v then ctrl-[ )0;Enter_Title_String_Here( ctrl-v then ctrl-g )"( enter )

ctrl-v : means hold down ctrl key and hit v at the same time like you are pasting in windoze ; also please don't type the parentheses, i.e., ( and )

echo $RANDOM