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.

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



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,363 results
unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

eject -T [cdrom_device]
2009-02-25 23:53:03
User: raphink
Functions: eject
Tags: device

Opens or closes the cdrom device.

echo | grep -P '^((25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])\.){3}(25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])$'
2009-09-17 12:59:44
User: foob4r
Functions: echo grep

This obey that you don't match any broadcast or network addresses and stay between -

cat /proc/version
openssl rand 6 -base64
2011-10-05 14:24:41
User: Le_Jax

just change 6 to 9 or 12 or more (multiple of 3) to have bigger password

/usr/bin/snmpwalk -v 1 -c public| awk -F : '{print "netapp temp:" $4 }'
2011-11-10 01:04:00
User: ndhail
Functions: awk
Tags: awk snmp netapp

if you can use this depends on which netapp you have, this netapp is an FAS2020

sed -i 6,66d <filename>
2012-02-04 02:29:40
User: icsamples
Functions: sed
Tags: bash sed

Delete range of lines. Ex: Line 6 through 66 in .

du -s $(ls -l | grep '^d' | awk '{print $9}') | sort -nr
tar zcpvf backup.tgz $(find $HOME -maxdepth 1 -name '.*' -and -not -name '.')
2012-05-01 17:48:24
User: DavidAlfonso
Functions: find tar
Tags: backup

This will make a backup of all hidden files and folders in the home folder.

hashkey=`echo -ne <your-secret> | xxd -p`; openssl rc4 -e -nosalt -nopad -K $hashkey -in myfile.txt -out myfile.enc.txt
2012-10-31 12:17:44
User: vishnu81
Tags: openssl rc4

At times you will need to safeguard your files. Use OpenSSL's native rc4 encryption to do so.

'nopad' removes padding and 'nosalt' removes random salt being added to the file.

for i in `ls` ; do cd $i ; pwd; for f in `ls *.rar` ; do unrar e $f ; done ; cd .. ; done
2013-03-06 19:23:58
User: Avelinux
Functions: cd

In order to unrar several files in different subfolders, you just need to launch this command in your parent folder in order to have your files ready for manipulation and already extracted;

I did not put anything to delete the original rar files

mplayer -dumpstream -dumpfile stream_video_name url
2013-12-13 18:28:16
User: pascalfares

1. Copy the url of the streaming video mms://etc... or http://...

2. Open up a terminal.

3. the command

4. Wait for the stream dump.

composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png
2009-02-15 19:53:45
User: jimmac
Functions: sed

Use graphicsmagick or imagemagick to composite a RGBA image over a flat white background and discard the alpha channel.

egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
2009-08-14 07:31:00
User: peshay
Functions: awk egrep

You can use that to create a excludefile for nmap, to find hosts, with no DHCP lease in your DHCP range.

blockdev --getsize64 /dev/sd[ab]
2011-01-08 11:25:54
User: bbelt16ag
Tags: blockdev

Compare the disk space for the new and old drive

FILE=$(tempfile 2>/dev/null || echo .$RANDOM)
2011-08-31 10:39:11
User: s123iva
Functions: echo
Tags: dash notify

enter our information on the content file.

cat table-mv.txt | perl -pe 's{([^;]+);([^;]+)}{tbl$1/tbl$2}' | perl -pe 's{(\S+)}{perl -i -pe #s/$1/g# xxx.sql}' | tr "#" "\'" | bash
2011-10-05 15:55:34
User: hute37
Functions: cat perl tr

with a semicolon text file map, apply multiple replace to a single file

sudo echo "package url" >> /etc/apt/sources.list
2012-05-01 21:32:51
User: Gunni
Functions: echo sudo

">>" appends to the file

">" replaces the entire file

make sure to use ">>"

cat item_list | xargs -n1 -P<n> process_item
find . -name ".DS_Store" -print0 | xargs -0 rm -rf
tar --exclude-from=$excludefile -zcvp "$source" | openssl aes-128-cbc -salt -out $targetfile -k $key
2013-12-13 19:35:20
User: klausman
Functions: tar

Create compressed, encrypted backup from $source to $targetfile with password $key and exclude-file $excludefile

/usr/bin/lynx -dump -width 500 | grep GET | awk '{print $12}' | sort | uniq -c | sort -rn | head
2014-03-12 12:31:34
User: copocaneta
Functions: awk grep sort uniq

Easiest way to obtain the busiest website list (sorted by number of process running).

ssh -D 8080 -f -N srv1
2014-06-25 12:46:44
User: fr00tyl00p
Functions: ssh

Provides a SOCKS5 proxy on localhost port 8080 which will tunnel all connections through srv1 and run in the background.

<command> | curl -F 'clbin=<-' https://clbin.com
2014-10-21 13:02:18
User: colemar

Define alias for convenience:

alias clbin='curl -v -F "clbin=<-" https://clbin.com'

Paste man page:

man bash | clbin

Paste image:

curl -F [email protected]' https://clbin.com
perl -e 'use strict; use warnings; my $c; my $file = $ARGV[0]; open my $handle, "<", $file or die "$0: $file: $!\n"; while (<$handle>) { print $c++, " " x 5, $_; } close($handle);' <FILE>
2009-12-09 16:07:14
User: sputnick
Functions: perl

This is a joke for @putnamhill and @glaudiston

I'm pretty sure we can write longer if we want ;)