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
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 [email protected]=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))'
awk -F: '$3 > 999 { print $1 }' /etc/passwd
2011-12-30 14:47:10
User: rockenrola
Functions: awk
Tags: awk uid passwd
0

To distinguish normal users from system users. Specify an UID, to list all all users with UID bigger than that in /etc/passwd.

show_code() { pygmentize $1 | less -N }
2012-05-12 09:18:33
User: Flow
Functions: less
0

Uses pygments ( http://pygments.org/ ) to highlight the source code and a less pipe to scroll and show line numbers of the code.

find . | while read line; do test `stat -c %u $line` -eq 1003 && chown android:android $line && echo $line; done
watch -d=c -n3 'lsof -itcp -iudp -c php'
2013-03-14 01:24:50
User: AskApache
Functions: watch
Tags: lsof PHP watch
0

Shows files and processes of the command php

sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys [key to get here]
2013-07-23 08:29:40
User: phattmatt
Functions: get sudo
0

If you are an unlucky soul behind a corporate firewall you will likely find that downloading gpg keys is blocked. This is because the hkp protocol uses port 11371 by default to transfer the key.

By adding "hkp://" to the beginning of the hostname and ":80" to the end you are asking gpg to try using port 80 to connect (less likely to be blocked by a firewall). This relies on the remote server answering to requests over port 80.

icacls directory_or_file /remove:g group_or_user