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,232 results
find public_html/ -type d -exec chmod 775 {} \;
2011-07-23 19:27:27
User: Nichlas
Functions: chmod find

Uses find to find and chmod directories recursively.

debconf-copydb copydb configdb --config="Name: copydb" --config ="Driver: File" --config="Filename: ~/copydebconf.dat"
mplayer -cache 100 -dumpstream http://listen.di.fm/public3/drumandbass.pls -dumpfile music.mp3
2011-11-08 15:36:33
User: TheShadowFog

You wont hear anything when you run that command.

You must run:

mplayer music.mp3


sudo apt-get install mplayer
rm -rf /commands/by/fukr
find . -type f ! -perm /u+x -printf "\"%p\"\n" | xargs file | grep -i executable
2012-03-12 17:29:36
User: aaronjcopley
Functions: file find grep xargs

Helps to fix permissions when a user clobbers them in their home directory or elsewhere. Does not rely on file extension, but uses the `file` command for context.

find . -type f -name *.MP3 -print0 | xargs -0 -i rename .MP3 .mp3 {}
2012-04-29 02:44:44
User: pibarnas
Functions: find rename xargs

Using a for loop, rename all files with .MP3 extension to .mp3.

sudo dd if=/your.img of=/dev/rdiskx bs=1m
youtube-dl urldelvideoyoutube
for i in {0..255}; do echo -e "\e[38;05;${i}m\\\e[38;05;${i}m"; done | column -c 80 -s ' '; echo -e "\e[m"
grep -c "search_string" /path/to/file
2013-12-10 18:13:54
User: meatflag
Functions: grep

-c will count the number of times your search matches in the file.

sudo lshw -html > /tmp/hardware.html && xdg-open /tmp/hardware.html
2014-03-08 10:40:21
User: Sadi
Functions: sudo

entering this command as root may give more complete results, creating a tmp file, and immediately opening the file might be more useful

php -v
dd if=/dev/hda | ssh root@ 'dd of=/root/server.img'
2014-10-13 13:43:47
User: suyashjain
Functions: dd ssh

By this command you can take the snapshot of you harddisk (full) and create the image , the image will be directly store on remote server through ssh. Here i am creating the image of /dev/hda and saving it at as /root/server.img.

ls -l /dev/disk/by-id |grep -v "wwn-" |egrep "[a-zA-Z]{3}$" |sed 's/\.\.\/\.\.\///' |sed -E 's/.*[0-9]{2}:[0-9]{2}\s//' |sed -E 's/->\ //' |sort -k2 |awk '{print $2,$1}' |sed 's/\s/\t/'
2015-01-25 19:29:40
User: lig0n
Functions: awk egrep grep ls sed sort
Tags: zfs disk info

This is much easier to parse and do something else with (eg: automagically create ZFS vols) than anything else I've found. It also helps me keep track of which disks are which, for example, when I want to replace a disk, or image headers in different scenarios. Being able to match a disk to the kernels mapping of said drive the disks serial number is very helpful

ls -l /dev/disk/by-id

Normal `ls` command to list contents of /dev/disk/by-id

grep -v "wwn-"

Perform an inverse search - that is, only output non-matches to the pattern 'wwn-'

egrep "[a-zA-Z]{3}$"

A regex grep, looking for three letters and the end of a line (to filter out fluff)

sed 's/\.\.\/\.\.\///'

Utilize sed (stream editor) to remove all occurrences of "../../"

sed -E 's/.*[0-9]{2}:[0-9]{2}\s//'

Strip out all user and permission fluff. The -E option lets us use extended (modern) regex notation (larger control set)

sed -E 's/->\ //'

Strip out ascii arrows "-> "

sort -k2

Sort the resulting information alphabetically, on column 2 (the disk letters)

awk '{print $2,$1}'

Swap the order of the columns so it's easier to read/utilize output from

sed 's/\s/\t/'

Replace the space between the two columns with a tab character, making the output more friendly

For large ZFS pools, this made creating my vdevs immeasurably easy. By keeping track of which disks were in which slot (spreadsheet) via their serial numbers, I was able to then create my vols simply by copying and pasting the full output of the disk (not the letter) and pasting it into my command. Thereby allowing me to know exactly which disk, in which slot, was going into the vdev. Example command below.

zpool create tank raidz2 -o ashift=12 ata-... ata-... ata-... ata-... ata-... ata-...
convert panorama_rainbow_2005.jpg -resize 40% panorama_rainbow_compress.jpg
2009-02-15 08:24:50
User: pcardout

convert -resize 750?500 -quality 80% *.jpg

These are command-line invocations of ImageMagick functions. The first sizes an image file to 40% of original and saves it to a different name, while the second makes all jpg files in a directory sized to 750x500 pixels. Such a pleasure not to need to point and click to make a bunch of thumbnails -- for example.

ffmpeg -i "/path/to/file.mp4" "/path/to/file.avi"
sed 's/,/\t/g' report.csv > report.tsv
2009-07-23 15:39:03
User: viner
Functions: sed

Convert comma separated files to tab separated files.

(MySQL eats tab separated files with much less instruction than comma seperated files.)

pattern='regexp_pattern'; find . -type f -perm +220 ! -name '*.bak' -print0 | xargs -0 egrep -lZ $pattern | xargs -0 sed -i.bak -e "/$pattern/d"
cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq
2010-04-08 08:51:17
User: chronosMark
Functions: cat cut egrep sed sort tr uniq

Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server.

tr A-Z a-z | tr -d 0-9\[\],\*-.?\:\"\(\)#\;\<\>\@ | tr ' /_' '\n' | sort | uniq -c
urpmi.addmedia --update google-talkplugin http://dl.google.com/linux/talkplugin/rpm/stable/$(uname -m | sed -e "s/i.86/i386/")
2011-04-30 23:01:36
User: mpb
Functions: sed uname

This command adds a urpmi media source called "google-talkplugin" to the urpmi configuration on Mandriva or Mageia. Needs to be run as root. We specify the option "--update" so that when Google provides a newer version of Google Talk plugin in their download system then running a system update (eg: "urpmi --auto-update") will result in our copy of Google Talk plugin getting updated (along with any other Mandriva/Mageia pending updates).

To install Google Talk plugin from this source, use:

urpmi google-talkplugin # install plugin used for voice and video Google chat via gmail

sed -r 's/(\[|])//g' | awk ' { $1=strftime("%D %T",$1); print }'
2012-02-03 13:07:37
User: Zulu
Functions: awk sed
Tags: sed awk timestamp

It remove the square bracket and convert UNIX time to human readable time for all line of a stream (or file).

qdbus org.freedesktop.PowerManagement /org/kde/Solid/PowerManagement suspendToRam
echo http://www.TheWebSiteName.com privatekeyword | md5sum | awk '{print substr($0,0,10)}'
2012-06-28 11:32:08
User: ertjies
Functions: awk echo md5sum

Create a bash function for easy reference



echo $1 $2 | md5sum | awk '{print substr($0,0,10)}'


alias webpwd=webPassword

Use like this.

webpwd www.commandlinefu.com MyPetNameHere

for s in /tmp/screens/S-$USER/*; do screen -r "$(basename "$s")"; done