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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
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,426 results
jshon -e addons -a -e defaultLocale -e name -u < ~/.mozilla/firefox/*.[dD]efault/extensions.json
zgrep 'pattern' /var/logs/apache2/access.log* | awk '{print $7}' | sort -n | uniq -c | sort -rn
find DIR -name "FILE" -exec grep -IHn STRING {} \;
ipconfig getpacket en0 | grep yi| sed s."yiaddr = "."en0: ". ipconfig getpacket en1 | grep yi| sed s."yiaddr = "."en1: ".
grep -ir 'foo' * | awk -F '{print $1}' | xargs vim
setterm -bfreq 0
2009-11-16 17:34:39
User: mvrilo
Functions: setterm
Tags: bell speaker beep
0

or change the frequency of the beep

wait
2010-01-15 04:03:11
User: bhepple
Functions: wait
0

If you really _must_ use a loop, this is better than parsing the output of 'ps':

PID=$! ;while kill -0 $PID &>/dev/null; do sleep 1; done

kill -0 $PID returns 0 if the process still exists; otherwise 1

rec -r 44100 -p | sox -p "audio_name-$(date '+%Y-%m-%d').ogg" silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d
2011-02-17 08:55:01
User: FuFighter
Tags: record
0

Very useful for recording radio scanner for instance as the resulting audio file contains only audio signal that exceeds -45dB and the file name tells you when the recording was done.

Why waste time listening silence? ;)

while [$((or_sz=$(stat -c %s "$1"))) -gt $((ds_sz=$(stat -c %s "$2")))];do ((pct=(69*$ds_sz)/$or_sz));echo -en "\r[";for ((i=1;i<=pct;i++));do echo -n "=";done;echo -n \>;for ((i=pct;i<=68;i++));do echo -n ".";done;echo -n "] $(((100*$pct)/69))%";done
2011-07-29 17:41:56
User: ScriptFanix
Functions: echo stat
0

Cleaner, but probably less portable. Works with bash4 and should also work on bash3.

IIRC, $(()) and (()) are bashisms, not POSIX.

zcat /usr/share/man/man1/man.1.gz | nroff -man | less
2011-09-07 01:13:57
User: atoponce
Functions: zcat
Tags: man less zcat nroff
0

As odd as this may be, I know of servers where the man(1) command is not installed, and there is not enough room on / to install it. However, zcat(1), nroff(1) and less(1) are. This is a way to read those documents without the proper tool to do so, as sad as this may seem. :)

diff -u <(ssh -t [email protected] sudo cat /dir1/file1) <(ssh -t [email protected] sudo cat /dir2/file2)
A=$(ip addr show dev eth0); A=${A##*inet }; echo ${A%%/*}
2013-03-13 23:07:37
User: charley
Functions: echo
0

bash only - no grep, sed, awk, whatever - zero overhead

alternatively using ifconfig instead of "ip addr ..."

A=$(ifconfig eth0); A=${A##*inet addr:}; echo ${A%% *}

rsync -arvx --numeric-ids --stats --progress --bwlimit=1000 file server:destination_directory
2013-10-01 13:00:59
Functions: file rsync
Tags: Linux rsync
0

Useful for transferring large file over a network during operational hours

mysqldump --force -uUSER -pPASS PRODUCTION_DB | mysql -uUSER -pPASS COPY_DB
2014-01-02 19:04:50
User: bones
0

this command uses mysqldump to dump the production database and pipe it directly to the copy-database

xxd -l 20 -c 20 -p /dev/urandom
2014-03-26 09:44:04
User: jt
Tags: password
0

Dumps 20 bytes from /dev/urandom and converts them to hex. -c and -p are needed to prevent splitting over lines.

sed -n '/url/s#^.*url=\(.*://.*\)#\1#p' ~/.mozilla/firefox/*.[dD]efault/SDBackups/*.speeddial | sort | uniq
2015-02-17 20:56:28
User: return13
Functions: sed sort
0

For all users of https://addons.mozilla.org/de/firefox/addon/speed-dial/

write user anytext
watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
2009-03-29 06:53:09
User: jnash
Functions: bc watch
0

Might be more useful if you were able to print it in Days HH:MM:SS format as:

perl -e '@p=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);'

But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

vim ~/.purple/pounces.xml
2009-04-28 19:11:39
Functions: vim
Tags: vim pidgin
0

So you keep getting buzzes sounding from pidgin but you can't remember which buddy pounce is causing the beep. Well, cat/edit the ~/.purple/pounces and find out!

ls -t1 | head -n1 | xargs tail -f
find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }'
2010-05-12 17:21:12
User: johnss
Functions: awk find ls xargs
0

This is an updated version that some one provided me via another "find" command to find files over a certain size. Keep in mind you may have to mess around with the print values depending on your system to get the correct output you want. This was tested on FC and Cent based servers. (thanks to berta for the update)

wmic process list IO
2010-08-20 11:05:34
User: glaudiston
0

there's some options, see more details in :

wmic /?

wmic process /?

wmic process list /?

pi 62999 | tr 0-9 del\ l\!owrH
2011-07-29 22:47:53
User: maurol
Functions: tr
Tags: bash pi
0

Pi also says hello world!

python -c 'import string, random; print "".join(random.choice(string.letters+string.digits) for x in range(6))'