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.

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





Maintained by Jon H.

Site originally by David Winterbottom (user root).

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using true from sorted by
Terminal - Commands using true - 23 results
while true ; do fswebcam -d /dev/video0 -r 1280x1024 -F 15 - | uuencode $(date +\%Y\%m\%d\%H\%M).jpeg | mail -s "Video surveillance" me@gmail.com ; sleep 300 ; done
2016-08-09 14:22:45
User: pascalv
Functions: date mail sleep true uuencode

This takes a picture (with the web cam) every 5 minutes, and send the picture to your e-mail.

Some systems support

mail -a "References: "

so that all video surveillance emails are grouped in a single email thread.

To keep your inbox clean, it is still possible to filter and move to trash video surveillance emails (and restore these emails only if you really get robbed!)

For instance with Gmail, emails sent to me+trash@gmail.com can be filtered with "Matches: DeliveredTo:me+trash@gmail.com"

while true ; do wget --quiet --no-check-certificate --post-data 'login=my_account_number&password=my_password&submit=Valider' 'https://wifi.free.fr/Auth' -O '/dev/null' ; sleep 600; done
2016-07-23 16:34:42
User: pascalv
Functions: sleep true wget
Tags: wifi France

(In French) Connection aux hotspots FreeWifi, et maintien de la connection active

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.

while ( true ) ; do if [ $(expr $RANDOM % 2 ) -eq 0 ] ; then echo -ne "\xE2\x95\xB1" ; else echo -ne "\xE2\x95\xB2" ; fi ; done
2015-01-17 12:46:37
User: tobi
Functions: echo expr true

Generates labyrinth-like pattern on UTF-8 terminal in bash.

For fun ;)

mkfifo fifo; while true ; do echo "Waiting for new event"; nc -l 8080 < fifo | tee -a proxy.txt /dev/stderr | nc 80 > fifo ; done
2015-01-14 09:26:54
User: ynedelchev
Functions: echo mkfifo tee true

If you have a client that connects to a server via plain text protocol such as HTTP or FTP, with this command you can monitor the messages that the client sends to the server. Application level text stream will be dumped on the command line as well as saved in a file called proxy.txt.

You have to change 8080 to the local port where you want your client to connect to. Change also to the IP address of the destination server and 80 to the port of the destination server.

Then simply point your client to localhost 8080 (or whatever you changed it to).

The traffic will be redirected to host on port 80 (or whatever you changed them to).

Any requests from the client to the server will be dumped on the console as well as in the file "proxy.txt".

Unfortunately the responses from the server will not be dumped.

pdfjam --clip true --trim '10mm 11cm 22pts 0' m.pdf
2014-07-08 10:57:54
User: qdrizh
Functions: true

This will crop each page of the PDF by 10mm left, 11cm bottom, 22pts right, and nothing from the top.

true | mailx -n -a MYTEXT.txt -r my@mail.com -s log -S smtp=mail.com -S smtp-auth-user=MYUSER -S smtp-auth-password=MYPASSWORD FRIEND@mail.com
2013-03-12 16:37:30
User: xmuda
Functions: mailx true

It is the best way i found to send a mail from the console in my centos server.

while true ; do killall mc ; done
2012-04-13 08:03:41
User: unixhero
Functions: killall true

I use this loop for a variety of things. If a process won't die, I try to ask it nicely to let it die gracefully, and then i use killall and kill -9 to end its life. This will run the program killall and then start it again when it completes, indefinately.

export GREP_COLOR='1;32';while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep --color=auto "ca fe"
while true ; do echo -n "`date`";curl localhost:3000/site/sha;echo -e;sleep 1; done
2011-10-14 21:00:41
User: donnoman
Functions: echo sleep true

In this case it runs the command 'curl localhost:3000/site/sha' waiting the amount of time in sleep, ie: 1 second between runs, appending each run to the console.

This works well for any command where the output is less than your line width

This is unlike watch, because watch always clears the display.

while true ; do sleep 1 ; clear ; (netstat -tn | grep -P ':36089\s+\d') ; done
2011-09-28 11:39:43
User: hute37
Functions: clear grep netstat sleep true

shell loop to scan netstat output avoiding loolback aliases (local/remote swap for local connections)

while true ; do nc -l 80 < index.html ; done
2011-08-31 15:17:33
User: ztank1013
Functions: true

Very simple web server listening on port 80 will serve index.html file or whatever file you like pointing your browser at http://your-IP-address/index.html for example.

If your web server is down for maintenance and you'd like to inform your visitors about it, quickly and easily, you just have to put into the index.html file the right HTML code and you are done! Of course you need to be root to run the command using port 80.

pdfnup --nup 2x1 --frame true --landscape --outfile output.pdf input.pdf
2010-12-21 14:20:06
User: TetsuyO
Functions: true

This is an example of the usage of pdfnup (you can find it in the 'pdfjam' package). With this command you can save ink/toner and paper (and thus trees!) when you print a pdf.

This tools are very configurable, and you can make also 2x2, 3x2, 2x3 layouts, and more (the limit is your fantasy and the resolution of the printer :-)

You must have installed pdfjam, pdflatex, and the LaTeX pdfpages package in your box.

Confirm() { echo -n "$1 [y/n]? " ; read reply; case $reply in Y*|y*) true ;; *) false ;; esac }
2010-11-22 16:54:16
User: eikenberry
Functions: echo false read true
Tags: read

This version works across on all POSIX compliant shell variants.

while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep "ca fe"
true || false && echo true || echo false
2010-04-20 09:17:08
User: Sizeof
Functions: echo false true
Tags: Linux UNIX

You can do some boolean logic like

A or B then C else D using

or : ||

and : &&

So you can do some :

# false || false && echo true || echo false


# true || false && echo true || echo false


# false || true && echo true || echo false


# true || true && echo true || echo false


and so on ...

I use it like :

(ssh example.com 'test something') || $(ssh example.net 'test something') && echo ok || echo ko
function ends_in_y() { case $(date +%A) in *y ) true ;; * ) false ;; esac } ; ends_in_y && echo ok
2010-04-06 22:18:52
Functions: date echo false true

The shell has perfectly adequate pattern matching for simple expressions.

count="1" ; while true ; do read next ; if [[ "$next" = "$last" ]] ; then count=$(($count+1)) ; echo "$count" ; else count="1" ; echo $count ; fi ; last="$next" ; done
2010-03-30 04:02:29
User: dabom
Functions: echo read true
Tags: bash read Game

Really bored during class so I made this...

Basically, you hold period (or whatever) and hit enter after a second and you need to make the next line of periods the same length as the previous line...

My record was 5 lines of the same length.

It's best if you do it one handed with your pointer on period and ring on enter.

echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done
2009-12-19 19:05:04
User: psykotron
Functions: dd echo tr true
Tags: color

A bit different from some of the other submissions. Has bold and uses all c printable characters. Change the bs=value to speed up and increase the sizes of the bold and non-bold strings.

while true ; do du -sk testfile ; sleep 10 ; done
2009-08-14 11:39:52
User: Solaris
Functions: du sleep true

This command produces the output of "du -sk testfile" in every 10 seconds. You can change the command to be whatever you want.

while true ; do IFS="" read i; echo "$i"; sleep .01; done < <(tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]")
2009-07-22 03:59:07
Functions: dd echo grep read sleep tr true
Tags: color

Same as above but slooooow it down

true && { echo success;} || { echo failed; }
2009-04-02 01:49:25
Functions: echo true

This will perform one of two blocks of code, depending on the condition of the first. Essentially is a bash terniary operator.

To tell if a machine is up:

ping -c1 machine { echo succes;} || { echo failed; }

Because of the bash { } block operators, you can have multiple commands

ping -c1 machine && { echo success;log-timestamp.sh }|| { echo failed; email-admin.sh; }


Remember, the { } operators are treated by bash as a reserved word: as such, they need a space on either side.

If you have a command that can fail at the end of the true block, consider ending said block with 'false' to prevent accidental execution

while true ; do scripts/bootstrap.py ; ./manage.py runserver ; done
2009-03-27 04:43:54
User: taurus
Functions: true

I wrote a script called bootstrap.py to delete the database, then load a new database with initial values. With this single-line shell loop, when I need to make a schema change (which happens often in the early stages of some projects), I hit ctrl-C to stop the running Django server, then watch bootstrap.py do its thing, then watch the server restart.