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.


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

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,371 results
less -X /var/log/insecure
2016-06-24 13:53:49
User: sonic
Functions: less
2

From the manpage:

man less

-X or --no-init

Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

Bonus:

If you want to clear the screen after viewing a file this way that had sensitive information, hit or just type clear. Since is readily available, I don't know why less bothers to automatically clear. If you're viewing the file at all, chances are you want to see the output from it after you quit.

echo '"\e\C-i": "\C-awhile true; do ( \C-e ); inotifywait -q -e modify -e close_write *; done\e51\C-b"' >>~/.inputrc
2016-06-10 08:06:50
User: unhammer
Functions: echo
1

Assuming you've written all of

make -j hfst-tokenize && echo doavtter gr?dakursa|./hfst-tokenize --gtd tokeniser-gramcheck-gt-desc.pmhfst

and want that to execute every time you :w in vim (or C-xC-s in Emacs), just hit and it'll turn into

while true; do ( make -j hfst-tokenize && e doavtter gr?dakursa|./hfst-tokenize --gtd tokeniser-gramcheck-gt-desc.pmhfst ); inotifywait -q -e modify -e close_write *; done

with the cursor right before the ')'. Hit enter, and it'll run on each save.

Requires the package inotify-tools installed.

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
3

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
10

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
2

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
1

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
2

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
3

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
2

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