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



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

All commands from sorted by
Terminal - All commands - 12,380 results
cat user_public_key.pub | ssh root@<host> "cat | su -c 'mkdir -m 700 -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys' <user>"
git commit -m "$(curl -s http://whatthecommit.com/index.txt)";
wget -q -O - | strings | tail -n 2
2016-05-03 23:03:55
User: paulera
Functions: strings tail wget

The router Technicolor TC7200 has an exploit where the file is open for unauthenticated access. Even though it is binary, the 2 last strings are the username and password for the pages for router management. It can be read using the 'strings' command, 'hexdump -C' or a hexadecimal editor.

(default user/password = admin/admin)

Reveals more configuration, including SSID name and Key for the wifi network:

wget -q -O -

Hexadecimal dump of the file:

wget -q -O - | hexdump -C
bashrc-reload() { builtin exec bash ; }
command systemctl --no-page --no-legend --plain -t service --state=running
systemctl --no-page -t service -a --state running --no-legend
mplayer http://pub7.di.fm/di_ambient_aac?1 -user-agent "AudioAddict-di/ Android/5.1"
2016-04-29 23:41:17
User: sxiii

This commands does just two things: fakes user agent (the one was taken from recent Android app) and sends the (possibly) listener ID (it can be any - I put "1" here because it works like a charm - after the name of stream ?1 as you can see).

Look for the list of stations here: http://pub7.di.fm

Or here: https://goo.gl/pdhhpQ

Best regards, sxiii :)

for i in `ls`; do mv "$i" "`echo $i | sed s/.json/_20160428.json/`"; done
apt purge linux*{14..18}*
2016-04-20 07:44:55
User: ppq
Functions: apt

If, for example, you want to remove all kernels and headers but the last three versions, you can't use one of that magic all-in-one "remove old stuff" commands.

With this simple but elegant command you can remove a range of versions, or a list of versions with e.g. {14,16,20}.

scriptName="reorder_files.sh"; echo -e '#!/bin/sh\n' > "${scriptName}"; cat files.txt | while read file; do echo "touch ${file}; sleep 0.5;" >> "${scriptName}"; done; chmod +x "${scriptName}";
2016-04-19 11:52:00
User: programmer
Functions: cat chmod echo read

Create a bash script to change the modification time for each file in 'files.txt' such that they are in the same order as in 'files.txt'

File name for bash script specified by variable, 'scriptName'. It is made an executable once writing into it has been completed.

ls *.pdf | while read file; do newfile="${file##CS749__}"; mv "${file}" "${newfile}"; done;
ls *.pdf | while read file; do newfile="CS749__${file}"; mv "${file}" "${newfile}"; done;
touch files.txt; cat reorder_files.sh | while read line; do x=`echo $line | sed 's/touch \([a-z0-9\.]\+.*.pdf\);.*/\1/'`; echo $x >> files.txt ; done;
pkg update -nv | sed -n '/entire/{N;p;}'
2016-04-15 20:48:49
User: apaton
Functions: sed

Above example is upgrading Solaris from 11.1SRU20.0.5 to 11.2SRU15.0.5. Patches are not applied options "-nv" are for dryrun and verbose output.

head -n1 | xargs -I {} aws sts get-session-token --serial-number $MFA_ID --duration-seconds 900 --token-code {} --output text --query [Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]
2016-04-12 10:57:00
User: keymon
Functions: head xargs

You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token.

This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use:

`awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'`

You must adapt the command line to include:

* $MFA_IDis ARN of the virtual MFA or serial number of the physical one

* TTL for the credentials

echo Which way up? | flip.pl | cowsay | tac | sed -e "s,/,+,g" -e "s,\\\,/,g" -e "s,+,\\\,g" -e "s,_,-,g" -e "s,\^,v,g"
2016-04-08 11:41:44
User: mpb
Functions: echo sed tac

It's quite fun to invert text using "flip.pl" (ref: http://ubuntuforums.org/showthread.php?t=2078323 ).

Slightly more challenging is to flip a whole "cowsay". :-)

ASN=32934; for s in $(whois -H -h riswhois.ripe.net -- -F -K -i $ASN | grep -v "^$" | grep -v "^%" | awk '{ print $2 }' ); do echo " blocking $s"; sudo iptables -A INPUT -s $s -j REJECT &> /dev/null || sudo ip6tables -A INPUT -s $s -j REJECT; done
ss -t -o state established '( dport = :443 || dport = :80 )' | grep -Po '([0-9a-z:.]*)(?=:http[s])' | sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3
ss -t -o state established '( dport = :443 || dport = :80 )'|grep tcp|awk '{ print $5 }'|sed s/:http[s]*//g|sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3
for i in *.flac; do flac -d -c "${i}" |lame -h --preset 196 --ta "Artist Here" --tl "Disc Title Here" --add-id3v2 - "./MP3/$i.mp3"; done
function df_func { local dfts=$(ssh $1 "df -lP | tail -n +2 | sed 's/%//'"); echo $dfts | awk '$5 > 90 {exit 1}' > /dev/null; if [ $? == 1 ]; then echo -n "$1 "; echo $dfts | awk '$5 > 90 {printf "%s %d%%\n", $6, $5}'; fi }
find . -type f -printf '%T@ %TY-%Tm-%Td %TH:%TM:%.2TS %p\n' | sort -nr | head -n 5 | cut -f2- -d" "
2016-03-23 11:56:39
User: paulera
Functions: cut find head sort

The output format is given by the -printf parameter:

%T@ = modify time in seconds since Jan. 1, 1970, 00:00 GMT, with fractional part. Mandatory, hidden in the end.

%TY-%Tm-%Td %TH:%TM:%.2TS = modify time as YYYY-MM-DD HH:MM:SS. Optional.

%p = file path

Refer to http://linux.die.net/man/1/find for more about -printf formatting.


sort -nr = sort numerically and reverse (higher values - most recent timestamp - first)

head -n 5 = get only 5 first lines (change 5 to whatever you want)

cut -f2- -d" " = trim first field (timestamp, used only for sorting)


Very useful for building scripts for detecting malicious files upload and malware injections.

[ $[ $RANDOM % 6 ] == 0 ] && echo 'Bang!' || echo 'Click...'
2016-03-23 11:09:56
User: paulera
Functions: echo
Tags: bash fun

Shows "Bang!" in a chance of 1 out of 6, like in the original game with the gun (spin every round). Otherwise, echoes "Click...". If feeling brave you can also do:

[ $[ $RANDOM % 6 ] == 0 ] && echo 'Bang!' && a really killer command || echo 'Click...'
fortune -s | cowsay -f tux | lolcat -s 64
make your terminal interactive and fun