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



All commands from sorted by
Terminal - All commands - 12,422 results
for y in {1..10}; do for x in {1..10}; do echo -n "| $x*$y=$((y*x)) "; done; echo; done|column -t
2016-09-07 12:31:18
User: lpalgarvio
Functions: column echo

The multiplication table for math study

find . -name \*.pyc -delete
curl ipinfo.io
2016-09-04 08:23:25
User: MrTux

Return IP information about your external ip address with JSON format

host -t srv _ldap._tcp | sed "s/.*[ ]\([^ ]*\)[.]$/\1/g" | xargs -i ping -c 1 {} | grep -E "(statistics|avg)" | sed "s/^--- \([^ ]*\).*/,\1:/g"|tr -d "\n" | tr "," "\n" | sed "1d;s|^\([^:]*\).*=[^/]*/\([^/]*\).*|\2\t\1|g" |sort -n
2016-09-02 03:26:29
User: glaudiston
Functions: grep host ping sed sort tr xargs
Tags: ldap

This command line detect ldap hosts, by mandatory dns entry, then ping them to detect response average. based on ping response average it sorts and print the faster server in first output line

ifconfig | awk -F: '/inet addr:/ { sub(/\.[^.]+$/, "", $2); if (!seen[$2]++ && $2 != "127.0.0") print $2 }'
2016-09-01 14:02:43
User: chrismccoy
Functions: awk ifconfig
Tags: ifconfig awk

For machines that have many ip blocks spanning different Class C's, this will show which ones.

tail -v -f $(php -i | grep "^[ \t]*error_log" | awk -F"=>" '{ print $2; }' | sed 's/^[ ]*//g')
2016-08-31 12:13:31
User: paulera
Functions: awk grep sed tail

Runs "php -i", filter the error_log location, then watches it using "tail"

curl wttr.in/seville
$ sed "2s/$/ $(sed -n '4p' sound.desktop)/" sound.desktop
2016-08-23 02:50:31
User: pibarnas
Functions: sed

Using "", which allow bash commands to be interpreted by sed scripts, I've embedded a sed script in another sed substitution, in case, the 4th line of the file at the end of the second one.

rsync --daemon --port 1234 --no-detach -v --config rsyncd.conf
mv ~/html/*~ ~
2016-08-17 17:28:07
User: pascalv
Functions: mv
Tags: mv html CGI

This prevents access to old CGI code

Print everything after last slash
2016-08-17 07:10:33
User: qdrizh
Functions: last
Tags: sed

FQPN - Path = Filename

pip install --prefix $PWD -I pip
2016-08-16 06:02:17
User: yoyoyojomo
Functions: install

For subsequent commands in the prefixed path:

PYTHONPATH=$PWD/lib/python*/site-packages ./bin/pip --version
printf '%s-%s-%s-%s\n' $(grep -v "[A-Z]\|'" /usr/share/dict/british | shuf -n 4)
2016-08-15 08:13:10
User: hendry
Functions: grep printf

https://xkcd.com/936/ introduced us to what actually is a good password. Here's such an implementation.

Credit: quinq on #suckless

printf "\U$(printf '%x' $((RANDOM%79+128512)) )"
2016-08-11 15:59:59
Functions: printf
Tags: bash emoji

This will print a random emoji within the range of 1F600 - 1F64F, which includes all the face emoji.

Obviously, this will only show something meaningful if your terminal can display emoji, but it may be useful in scripts.

This likely requires recent versions of bash

curl -s httpbin.org/ip | jq -r .origin
while true ; do fswebcam -d /dev/video0 -r 1280x1024 -F 15 - | uuencode $(date +\%Y\%m\%d\%H\%M).jpeg | mail -s "Video surveillance" [email protected] ; 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 [email protected] can be filtered with "Matches: DeliveredTo:[email protected]"

ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
2016-08-04 10:59:58
User: gormux
Functions: awk grep ps strace xargs
Tags: awk grep ps strace

Will open strace on all apache process, on systems using sbin/apache (debian) or sbin/httpd (redhat), and will follow threads newly created.

gem install `ruby ./isuckat_ruby.rb 2>&1 | sed -e 's/.*find gem .//g' -e 's/ .*//g' | head -n 1`
2016-08-03 19:41:27
User: operat0r
Functions: head install sed

When bundle install sucks ...This runs isuckat_ruby.rb and when stderror matches find gem ' it will gem install what ever is missing ...

sed 'X{N;s/\n//;}' file.txt (where X is the current line)
2016-07-30 14:27:20
User: pibarnas
Functions: sed

N: On the current line, sed will display it on pattern space, plus a \n (new line); but

s/\n//: Will get rid of new line displayed on pattern space, joining the current line's end with the start of the next line

Useful in scripts.

links `lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort -R | uniq | head -n1`
2016-07-26 12:54:53
User: mogoh
Functions: grep head sort uniq

sort -R randomize the list.

head -n1 takes the first.

links $( a=( $( lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort | uniq ) ) ; amax=${#a[@]} ; n=$(( `date '+%s'` % $amax )) ; echo ${a[n]} )
2016-07-26 11:52:12
User: pascalv
Functions: echo grep sort uniq

Access a random news web page on the internet.

The Links browser can of course be replaced by Firefox or any modern graphical web browser.

2016-07-25 18:52:42
User: malathion

Replaces the first instance of 'foo' with 'bar'. To replace all instances of 'foo' with 'bar': !!:gs/foo/bar/

f=correlation.png; s=400; t=50; a=1.2; convert $f -resize ${s}% -threshold ${t}% bmp:- | potrace -o ${f%.*}.svg -b svg -z black --fillcolor "#FFFFFF" --alphamax ${a}
2016-07-25 10:45:28
User: T4b

Uses ImageMagick and potrace to vectorize the input image, with parameters optimized for xkcd-like pictures.

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

hpacucli controller all show config detail | grep -A 7 Fail | egrep '(Failed|Last|Serial Number|physicaldrive)'
2016-07-20 17:42:40
User: operat0r
Functions: egrep grep

This dumps serial numbers of all the drives but HP warranty check does not say they are valid ...