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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




Commands tagged Linux from sorted by
Terminal - Commands tagged Linux - 232 results
rsync -arvx --numeric-ids --stats --progress --bwlimit=1000 file server:destination_directory
2013-10-01 13:00:59
Functions: file rsync
Tags: Linux rsync

Useful for transferring large file over a network during operational hours

wbinfo -a username%password
echo 0$(awk '/Pss/ {printf "+"$2}' /proc/$PID/smaps)|bc
2013-09-26 18:20:22
User: atoponce
Functions: awk echo
Tags: Linux awk echo bc proc

The "proportional set size" is probably the closest representation of how much active memory a process is using in the Linux virtual memory stack. This number should also closely represent the %mem found in ps(1), htop(1), and other utilities.

echo "This is the message body" | mutt -s "Message subject" -a file_to_attach.zip fred@example.com
2013-09-26 08:05:26
User: jedifu
Functions: echo
Tags: Linux shell email

This uses mutt to send the file, and doesn't require uuencode etc

for f in ./*.xls; do mv "$f" "${f%.*}.ods"; done
2013-09-17 01:41:56
User: evilsoup
Functions: mv
Tags: bash Linux

An entirely shell-based solution (should work on any bourne-style shell), more portable on relying on the rename command, the exact nature of which varies from distro to distro.

rename 's/.xls/.ods/g' *.xls
for I in $(awk -v LIMIT=500 -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd | cut -f 1-1 -d ':' | xargs); do usermod -g YOURGROUP $I ; done
hciconfig;hciconfig -a hci0;lsmod |grep bt;dmesg | grep tooth
diff <(sort <(md5deep -b -r /directory/1/) ) <(sort <(md5deep -b -r /directory/2/)
2013-08-19 18:20:49
Functions: diff sort
Tags: bash Linux diff

Compares the md5 checksums of the contents of two directories, outputting the checksum and filename where any files differ. Shows only the file name, not the full path.

diff <(sort <(md5deep -r /directory/1/) |cut -f1 -d' ') <(sort <(md5deep -r /directory/2/) |cut -f1 -d' ')
2013-08-18 22:13:07
Functions: cut diff sort
Tags: bash Linux diff

Compute the md5 checksums for the contents of two mirrored directories, then sort and diff the results. If everything matches, nothing is returned. Otherwise, any checksums which do not match, or which exist in one tree but not the other, are returned. As you might imagine, the output is useful only if no errors are found, because only the checksums, not filenames, are returned. I hope to address this, or that someone else will!

wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '/<pre>/,/<\/pre>/p' | sed -n '/<table*/,/<\/table>/p' | sed '1d' | sed '$d' | recode html..ascii
for i in '/tmp/file 1.txt' '/tmp/file 2.jpg'; do ln -s "$i" "$i LINK"; done
2013-08-02 08:30:50
User: qwertyroot
Functions: ln


'/tmp/file 1.txt' '/tmp/file 2.jpg'



for Nautilus script

Or with


for Thunar action

If you linking the symlinks itself, but want to link to source files instead of symlinks, use

"`readlink -m "$i"`"

instead of


like this:

for i in '/tmp/file 1.txt' '/tmp/file 2.jpg'; do ln -s "`readlink -m "$i"`" "$i LINK"; done


for i in {1..31}; do ls -1 *${YYYY}${MM}`printf "%02d" $i`* | wc -l; done
2013-07-26 07:08:04
User: Paulus
Functions: ls wc
Tags: bash Linux

RU: Найдет число файлов в папке по данной маске в цикле по дням месяца

du -m --max-depth=1 [DIR] | sort -nr
strace -ttvfo /tmp/logfile -s 1024 program
2013-07-06 08:19:29
User: ryanchapman
Functions: strace
Tags: Linux strace

How to figure out what a program is doing.

-tt detailed timestamps

-f also strace any child processes

-v be very verbose, even with common structures

-o write output to file

-s N capture up to N characters of strings, rather than abbreviating with ...

mogrify -resize SIZE_IN_PIXELS *.jpg
2013-07-05 14:14:04
User: o0110o

Batch resize all images to a width of 'X' pixels while maintaing the aspect ratio.

This makes uses of ImageMagick to make life easier.

SSHPASS='your_password' sshpass -e ssh me@myhost.com
2013-06-03 12:26:40
User: djkadu
Functions: ssh

The above is OK if you not worried about security, as per sshpass man pages:

" The -p option should be considered the least secure of all of sshpass's options. All system users can see the password in the command line with a simple "ps" command."

So, instead what I do is use the -e option:

" -e The password is taken from the environment variable "SSHPASS"."

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
2013-05-24 14:33:38
User: o0110o
Functions: ssh

You need to install "sshpass" for this to work.

apt-get install sshpass

du -mx [directory] | grep -P '^\d{4}' | sort -rn
2013-05-24 09:52:41
User: mc0e
Functions: du grep sort
Tags: bash Linux du

I don't like doing a massive sort on all the directory names just to get a small set of them. the above shows a sorted list of all directories over 1GB. use head as well if you want.

du's "-x" flag limits this to one file system. That's mostly useful when you run it on "/" but don't want "/proc" and "/dev" and so forth. Remember though that it will also exclude "/home" or "/var" if those are separate partitions.

the "-a" option is often useful too, for listing large files as well as large directories. Might be slower.

du -xB M --max-depth=2 /var | sort -rn | head -n 15
sudo apt-cache dumpavail | grep Package | cut -d ' ' -f 2 > available.packages
netstat -tuapen | grep LISTEN
fsarchvier probe simple
mencoder FILENAME.3gp -ovc lavc -lavcopts vcodec=msmpeg4v2 -oac mp3lame -lameopts vbr=3 -o FILENAME.avi
ssh user@remote "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 user@remote:/remote/music/dir/ /mnt/other_pc/