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.

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



All commands from sorted by
Terminal - All commands - 12,323 results
bind '"<ctrl+v><functionKey>":"command\n"'
2015-05-11 17:59:09
User: nnsense

This is a common use of bind. Hitting any key after will output the key's character sequence. This makes possible using it into a bind command. So pressing ctrl+v and then F2 will output "^[[12~", once binded every time you'll press the function key F2 it will execute your command. Added the \n to make it execute it as well.

mosth() { history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10; }
2015-05-11 17:41:55
User: nnsense
Functions: awk column grep head nl sort

I copied this (let's be honest) somewhere on internet and I just made it as a function ready to be used as alias. It shows the 10 most used commands from history. This seems to be just another "most used commands from history", but hey.. this is a function!!! :D

fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
2015-05-11 16:46:01
User: nnsense
Functions: basename echo grep rpm whatis

Many times I give the same commands in loop to find informations about a file. I use this as an alias to summarize that informations in a single command. Now with variables! :D

qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
2015-05-11 16:32:16
User: nnsense
Functions: grep rpm

I use this as an alias to get all .service files related a single installed file/conf (if it has services, of course).

For rpm based systems ;)

cdls() { if [[ $1 != "" ]] ; then cd $1; ls; else ls; fi };
2015-05-11 15:52:09
User: nnsense
Functions: cd

Not really alternative, just giving a different behavior listing current directory if no directory given.

for x in `ls -1`; do $SOMETHING; done
curl -s https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/ | grep -o '[^"]*Linux/7/pdf[^"]*' | xargs -I{} wget https://access.redhat.com{}
2015-05-11 11:57:20
User: SuperFly
Functions: grep wget xargs

Let's give Flatcap credit for this elegant solution, instead of leaving it hidden as a comment.

Tested on RHEL6 and it works. Nice and clean.

uudeview +e .zip -i mail.eml
2015-05-11 10:32:49
User: MaxChinni

Extract any ".zip" attachment from the e-mail.

du -hs .[^.]* * | sort -h
2015-05-10 12:19:29
User: liminal
Functions: du sort
Tags: du usage disk

Same result as with 'du -ks .[^.]* * | sort -n' but with size outputs in human readable format (e.g., 1K 234M 2G)

locate -i /pattern/ | xargs -n1 dirname | sort -u
2015-05-09 21:22:05
User: dardo1982
Functions: dirname locate sort xargs
Tags: find case

Uses "locate" instead of "find", "sort -u" instead of "sort | uniq" and it's case insensitive.

perl -pE's/(\S+\s*){0,1}//'
2015-05-09 15:14:58
User: pung96
Functions: perl

An advantage is that this doesn't modify remained string at all. One can change {0,1} with {0,n} to drop several columns

echo FileName | perl -nlE'sleep 1 while time-(stat)[10]<10' && echo DONE
2015-05-09 14:58:41
User: pung96
Functions: echo perl

perl version of "Wait for file to stop changing"

When "FileName" has not been changed for last 10 seconds, then print "DONE"

"10" in "(stat)[10]" means ctime.

One have other options like atime, mtime and others. http://perldoc.perl.org/functions/stat.html

while [ $(( $(date +%s) - $(stat -c %Y FILENAME) )) -lt 10 ]; do sleep 1; done; echo DONE
2015-05-09 12:30:13
User: flatcap
Functions: date echo sleep stat

This loop will finish if a file hasn't changed in the last 10 seconds.


It checks the file's modification timestamp against the clock.

If 10 seconds have elapsed without any change to the file, then the loop ends.


This script will give a false positive if there's a 10 second delay between updates,

e.g. due to network congestion


How does it work?

'date +%s' gives the current time in seconds

'stat -c %Y' gives the file's last modification time in seconds

'$(( ))' is bash's way of doing maths

'[ X -lt 10 ]' tests the result is Less Than 10

otherwise sleep for 1 second and repeat


Note: Clever as this script is, inotify is smarter.

echo $(date +%m) past $(date +%H) | espeak
2015-05-09 12:24:13
User: hal8
Functions: date echo

s/espeak/say/ on a mac

diff <(ssh $remote_site cat $file) $file
2015-05-09 11:11:56
User: hal8
Functions: cat diff ssh

opens the output of some command as a file so this also works with graphical editors like meld, kdiff3 etc

meld <(ssh $remote_site cat .zshrc) .zshrc
ps aux
echo -e $_{1..80}'\b+'
sleep 10 & perl -e [email protected]=qw(-Ooooo \oOooo |ooOoo /oooOo -ooooO \oooOo |ooOoo /oOooo);while(kill 0,'$!'){ print "\r",$s[$t++%($#s+1)];select(undef,undef,undef,0.2);}'
while [ "$(ls -l --full-time TargetFile)" != "$a" ] ; do a=$(ls -l --full-time TargetFile); sleep 10; done
2015-05-09 03:19:49
User: dmmst19
Functions: ls sleep

Here's a way to wait for a file (a download, a logfile, etc) to stop changing, then do something. As written it will just return to the prompt, but you could add a "; echo DONE" or whatever at the end.

This just compares the full output of "ls" every 10 seconds, and keeps going as long as that output has changed since the last interval. If the file is being appended to, the size will change, and if it's being modified without growing, the timestamp from the "--full-time" option will have changed. The output of just "ls -l" isn't sufficient since by default it doesn't show seconds, just minutes.

Waiting for a file to stop changing is not a very elegant or reliable way to measure that some process is finished - if you know the process ID there are much better ways. This method will also give a false positive if the changes to the target file are delayed longer than the sleep interval for any reason (network timeouts, etc). But sometimes the process that is writing the file doesn't exit, rather it continues on doing something else, so this approach can be useful if you understand its limitations.

tr -s ' ' | cut -d' ' -f2-
du -ks .[^.]* * | sort -n
2015-05-08 12:26:34
User: rdc
Functions: du sort
Tags: du usage disk

This command summarizes the disk usage across the files and folders in a given directory, including hidden files and folders beginning with ".", but excluding the directories "." and ".."

It produces a sorted list with the largest files and folders at the bottom of the list

while kill -0 0; do timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for _ in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'; done
2015-05-07 19:13:08
User: anapsix
Functions: bash echo kill seq sleep

alternatively, run the spinner for 5 seconds:

timeout 5 bash -c 'spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); while true; do for i in ${spinner[@]}; do for j in seq 0 ${#i}; do echo -en "\b\b"; done; echo -ne "${i}"; sleep 0.2; done; done'

i=in.swf; dump-gnash -1 -j 1280 -k 720 -D "${i%.*}".[email protected] -A "${i%.*}".wav "${i}"
2015-05-06 23:52:39
User: mhs

This will dump a raw BGRA pixel stream and WAV which must then be converted to video:

ffmpeg -f rawvideo -c:v rawvideo -s 1280x720 -r 12 -pix_fmt bgra -i "${i%.*}".bgra -c:v libx264 -preset veryslow -qp 0 -movflags +faststart -i "${i%.*}".wav -c:a libfdk_aac -b:a 384k "${i%.*}".mp4 ; rm "${i%.*}".bgra "${i%.*}".wav

Our example generates an x264/720p/12fps/AAC best-quality MP4.

To get dump-gnash, first install the build-dependencies for gnash (this step is OS-specific). Then:

git clone http://git.savannah.gnu.org/r/gnash.git ; cd gnash ; ./autogen.sh ; ./configure --enable-renderer=agg --enable-gui=dump --disable-menus --enable-media=ffmpeg --disable-jemalloc ; make
wget -q -O- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/ | grep Linux/7/pdf | cut -d \" -f 2 | awk '{print "https://access.redhat.com"$1}' | xargs wget
tail -f /var/squid/logs/access.log | perl -pe 's/(\d+)/localtime($1)/e'