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,325 results
ssh [email protected] "cat /remote/music/dir/*.mp3" | mpg123 -
2013-02-15 20:03:21
User: erix
Functions: mpg123 ssh
Tags: ssh Linux mpg123

This is just a quick and dirty way to play remote audio files *locally* in your PC.

The best way is to mount the remote Music directory into the local FS, say by using sshfs:

sshfs [email protected]:/remote/music/dir/ /mnt/other_pc/

ping -n 1 -w 10000
2009-08-26 02:25:07
User: DocGyver
Functions: ping

In the vein of "can you do it better", here is my take on using "ping" to emulate sleep in a DOS/BAT script. If one can use ping at all then the multicast address will be valid but will not respond. By doing only one ping (-n 1) and setting a timeout in milliseconds (-w 10000) you have a fairly accurate timer. This example gives about a 10 second sleep.

ls -l directory | awk 'BEGIN { SUM=0 } { SUM+=$5 } END { print SUM/1024/1024"M" }'
convert -quality 40% original_image reduced_image
for L in `echo :$PATH | tr : '\n'`; do F=${L:-"."}/fileName; if [ -f ${F} -o -h ${F} ]; then echo ${F}; break; fi; done
2009-09-11 16:14:36
User: arcege
Functions: echo tr

Searches in order of the directories of $PATH. Stops after finding the entry; looks for only that fileName. Works in Bourne, Korn, Bash and Z shells.

ffmpeg -i input.flv -vhook '/usr/lib/vhook/imlib2.so -c white -x 250 -y H+(-1.8*N+80) -t Hallo! -A max(0,255-exp(N/16))' -sameq -acodec copy output.flv
find -type f -exec du -sh {} + | sort -rh | head
find . -name '*.txt' -exec mv {} {}.sh \ ;
2011-06-02 23:47:19
Functions: find mv

You can replace "." with your folder

MAC=$((date +'%Y%m%d%H%M%S%N'; cat /proc/interrupts) | md5sum | sed -r 's/(..)/\1:/g' | cut -d: -f 1-6)
2011-07-14 13:11:50
User: jazznjam
Functions: cat cut date md5sum sed

I liked vaporub's suggestion, here a little simplification of the sed command.

convert example.png -resize 100x100 output.png
2010-08-08 16:40:21
User: dbbolton

You can also specify width and height of the resized image (in pixels), as an alternative to using a percentage.

find . -name "*.png" | tee images.txt | grep book
2011-06-02 23:55:50
Functions: find grep tee

You can find every file with png extension and redirect its output to file. Later you can find a string inside the file.

cp -dpRx /* /mnt/target/
2011-08-22 14:22:01
Functions: cp

preserve all except context and xattr. useful when moving a running system to a new partition.

vgdisplay -v 2>/dev/null | grep "^ LV Name" | while read A B LVDEV; do echo $LVDEV; done
NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)
2010-06-04 07:58:53
User: keymon
Functions: mount perl umount

Based on the execute with timeout command in this site.

A more complex script:


# This script will check the avaliability of a list of NFS mount point,

# forcing a remount of those that do not respond in 5 seconds.


# It basically does this:

# NFSPATH=/mountpoint TIMEOUT=5; perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $NFSPATH" || (umount -fl $NFSPATH; mount $NFSPATH)



SCRIPT_NAME=$(basename $0)

for i in $@; do

echo "Checking $i..."

if ! perl -e "alarm $TIMEOUT; exec @ARGV" "test -d $i" > /dev/null 2>&1; then

echo "$SCRIPT_NAME: $i is failing with retcode $?."1>&2

echo "$SCRIPT_NAME: Submmiting umount -fl $i" 1>&2

umount -fl $i;

echo "$SCRIPT_NAME: Submmiting mount $i" 1>&2

mount $i;



cat /etc/passwd | wc -l
iostat -En $(iostat -en|grep c#t|awk '$2 > 0 {print $NF}')
2011-12-09 15:54:28
Functions: awk grep

This helps quickly get information for each disk that is seemingly having hardware issues.

2009-03-25 07:25:33
User: dizzgo
Tags: Ubuntu

release upgrades are major upgrades as from 8.04 to 8.10 or from 8.10 to 9.04

update-manager-core must be installed:

sudo apt-get install update-manager-core

in some cases you must edit '/etc/update-manager/release-upgrades' and set 'Prompt=normal'

recoll -t -q "keyword" | grep message/rfc822 | sed -s 's,^.*\('$MAILDIR'[^]]*\)\].*$,\"\1\",' | xargs ln -sft $MAILDIR/bingo/cur/
ls -d */* | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs mv -t $(pwd)
2010-03-01 23:43:26
User: leovailati
Functions: ls mv sed xargs

You WILL have problems if the files have the same name.

Use cases: consolidate music library and unify photos (especially if your camera separates images by dates).

After running the command and verifying if there was no name issues, you can use

ls -d */ | sed -e 's/^/\"/g' -e 's/$/\"/g' | xargs rm -r

to remove now empty subdirectories.

dc -e "1 1 + p"
ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
2012-08-15 15:04:48
User: plasticboy
Functions: find
Tags: find simple

These should be a little faster since they don't have to spawn grep.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged.pdf -dBATCH `ls | grep foo`
perl -e 'print 1+1 ."\n";'
echo | socat -u - file:/tmp/swapfile,create,largefile,seek=10000000000000
gzip -c source.csv > source.csv.gz
2012-10-17 18:31:51
User: cfunz
Functions: gzip
Tags: gzip aix

use this command to gzip the file and write to stdout and from the stdout redirect to the another file