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,392 results
echo "https://www.google.com/maps/place/$(exiftool -ee -p '$gpslatitude, $gpslongitude' -c "%d?%d'%.2f"\" image.jpg 2> /dev/null | sed -e "s/ //g")"
2016-06-09 13:33:10
User: mpb
Functions: echo

This command uses the "exiftool" command which is available here: http://www.sno.phy.queensu.ca/~phil/exiftool/

NB, there should be a degree symbol right after the first "%d" NOT a question mark.

For some unknown reason, commandlinefu is not able to handle degree symbol correctly ("?")?

rsync -a --delete empty-dir/ target-dir/
2016-06-07 16:56:55
User: malathion
Functions: rsync
Tags: delete rsync

This command works by rsyncing the target directory (containing the files you want to delete) with an empty directory. The '--delete' switch instructs rsync to remove files that are not present in the source directory. Since there are no files there, all the files will be deleted.

I'm not clear on why it's faster than 'find -delete', but it is.

Benchmarks here: https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html

sudo mount -o remount,rw / && sudo cp /etc/hosts /etc/hosts.old && wget http://winhelp2002.mvps.org/hosts.txt && cp /etc/hosts ~/ && cat hosts.txt >> hosts && sudo cp hosts /etc/hosts
2016-06-06 15:01:19
User: bugmenot
Functions: cat cp mount sudo wget

Will append lines to the hosts file to do some basic ad blocking.

curl --silent --head "${url}" | grep 'Last-Modified:' | cut -c 16- | date -f - +'%s'
2016-06-02 22:20:55
User: odoepner
Functions: cut date grep

This command line assumes that "${url}" is the URL of the web resource.

It can be useful to check the "freshness" of a download URL before a GET request.

curl http://url/rss | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
tree -isafF /var|grep -v "/$"|tr '[]' ' '|sort -k1nr|head
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

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

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 - | 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;