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

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,130 results
curl -s -o /dev/null -w "%{http_code}\n" localhost
curl --write-out %{http_code} --silent --output /dev/null localhost
mencoder -speed 2 -o output.avi -ovc lavc -oac mp3lame input.avi
starts a CGI web server
2014-11-05 23:07:37
User: andreisid
2

In case you need to test some CGI scripts this does the job. It also has the functionality of a http server.

Enjoy!

grep VmHWM /proc/$(pgrep -d '/status /proc/' FOO)/status
2014-11-05 15:06:29
User: michelsberg
Functions: grep
2

Show the maximum amount of memory that was needed by a process at any time. My use case: Having a long-running computation job on $BIG_COMPUTER and judging whether it will also run on $SMALL_COMPUTER.

http://man7.org/linux/man-pages/man5/proc.5.html

VmHWM: Peak resident set size ("high water mark")

chmod +x myfile.py
export PATH=$PATH:/home/user/my_prog
grep 'font-family:[^;]*' <input file.svg> | sed 's/.*font-family:\([^;]*\).*/\1/g' | sort | uniq
2014-11-03 20:38:08
User: caiosba
Functions: grep sed sort
Tags: fonts svg
0

List all fonts used by an SVG file. Useful to find out which fonts you need to have installed in order to open/edit an SVG file appropriately.

sed -i 's/oldname/newname/' /etc/hosts /etc/hostname
2014-11-02 22:03:48
User: adria
Functions: sed
Tags: sed hostname host
1

With sed you can replace strings on the fly.

curl ifconfig.me
2014-11-02 21:57:52
User: adria
0

http://ifconfig.me is a web site which shows your public iP address.

If you want use your own code, you can use PHP code such as:

function getip()

{

return "".$_SERVER["REMOTE_ADDR"];

}

echo getip();

?>

Then, you'll get your IP by 'curl yourfile.php'.

grep -Eoa "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" Filetosearch.txt
2014-11-02 19:50:54
User: jsbrown
Functions: grep
0

Command returns valid IP addresses. Append the following regex to additionally filter out NAT and reserved IP addresses

| grep -Ev "^0|\.0[0-9]|^10\.|^127\.|^169\.|^172\.(1[6-9]|2[0-9]|3[01])|^192.168.|^2(2[4-9]|3[0-9])|^2(4[0-9]|5[0-5])"

cat File.txt | grep -io 'http://www.acme.com/a/files/.*.pdf'| uniq
for i in `lanscan -i | awk '{print $1}'` ; do ifconfig $i ; done 2> /dev/null
netstat -nr|egrep -v "Routing|Interface|lo0"|awk '{print $5}'|sort -u| while read l; do ifconfig $l ; echo " Station Addr: `lanscan -ia|grep "$l "|cut -d ' ' -f 1`" ; done
jhead -n%Y-%m-%d_%H-%M-%S__%f *.JPG
for i in `ls` ; do date=$(identify -format %[exif:DateTime] $i); date=${date//:/-}; date=${date// /_}; mv $i ${date}__$i; done
find -type f -exec ffmpeg -i "{}" "{}".mp3 \;
lsof -ns | grep REG | grep deleted | awk '{s+=$7/1024} END {print s}'
ip a s eth0 | sed -nr 's!.*inet ([^/]+)/.*!\1!p'
ls *.png | cut -d . -f 1 | xargs -L1 -i convert -strip -interlace Plane -quality 80 {}.png {}.jpg
find . -name *.png | xargs optipng -nc -nb -o7 -full
tar -cvf bind9-config-`date +%s`.tar *
2014-10-29 05:15:15
User: Fuonum
Functions: tar
-1

backup your files in tar archive + timestamp of backup

cut -d: -f1 /etc/group | sort
setxkbmap -option caps:backspace
2014-10-27 22:53:39
User: lgarron
0

The internet is full of advice about how to change the caps lock key into a backspace key (a useful practice that originated with Colemak), but a lot of instructions are complicated or outdated.

After *lots* of searching for something that still worked on Ubuntu 14.04, I finally found that this simple command is sufficient and takes effect immediately.

(Found at: http://www.howtogeek.com/194705/how-to-disable-or-reassign-the-caps-lock-key-on-any-operating-system/ )

=() {python3 -c "from math import *;print($*)"}