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,230 results
mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/
2011-04-14 17:02:05
User: depesz
Functions: gzip mkdir tar tee
Tags: bash tee tar

Sometimes you might need to have two copies of data that is in tar. You might unpack, and then copy, but if IO is slow, you might lower it by automatically writing it twice (or more times)

fileName() { echo "$1" | grep -o "[^/]*$"; }
2011-08-19 18:16:22
User: totti
Functions: echo grep
Tags: grep basename
fileName /path/to/file.ext

quivalent to

basename /path/to/file.ext
sudo npm cache clean -f | sudo npm install -g n | sudo n stable
svn log --stop-on-copy | grep r[0-9] | awk '{print $1}' | sed "s/r//" | sort -n | head -1
git branch -D `git branch | awk '{ if ($0 !~ /next|master/) printf "%s", $0 }'`
2011-04-14 17:43:21
User: denheck
Functions: awk printf

This command will delete all branches in your git repository other than next and master. I use this to cleanup my git repos after making multiple branches and merging them back into next. It's much faster than individually deleting each expired branch using:

git branch -D <branch_name>
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"
2009-02-09 01:54:05
User: bones7456
Functions: df grep

show physical disk using, except tmpfs, gvfs, and so on.

mkdir save && for f in *.mp3; do lame -b xxx "$f" ./save/"${f%.mp3}.mp3"; done
2011-05-30 17:19:36
User: o0110o
Functions: mkdir

Batch Convert MP3 Bitrate to xxxkbps, all the new files will be placed in a folder called "save". Please replace xxx with the desired bitrate. WARNING!!! This will erase any tag information; this is where Picard or EasyTAG will come in handy.

Amharic software
sleep 15 ; `echo "done" | mail -s "done" 4158575309@txt.att.net`
2012-04-16 01:28:16
User: vajrapani666
Functions: mail sleep

Replace "4158575309@txt.att.net" with your carrier's SMS gateway identifier. The one in the sample is for AT&T. More here https://en.wikipedia.org/wiki/List_of_SMS_gateways. Helpful for getting notifications about long running commands. ";" executes regardless of exit status of last command. && will only notify you if the command succeeds.

find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\('
2009-02-17 14:56:01
User: ubermuda
Functions: find grep xargs

finds all forms instanciated into a symfony project, pruning svn files.

top -bn 1 | awk '{if($1 ~ /^[0-9]+$/ && $9 > 97) {print $1;exit}}'|xargs kill
2010-06-02 13:51:40
User: chx
Functions: awk top xargs

I found Flash eating one of my CPUs after resume, the command above will help with that. For optional kicks you can put it into a script in /etc/pm/sleep.d/ (aspect in #swhack wrote this for me)

sudo sh /usr/share/doc/libdvdread4/install-css.sh
dd of=output.txt if=input.txt ibs=1 skip=$(expr `stat -c%s input.txt` / 2)
find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf
tb send xmpp:user.name@gmail.com
2013-04-08 00:29:43

After installing Termbeamer (see termbeamer.com) you can use it to share a terminal session with one or more others even from behind a firewall or NAT.

hg st --added -n |xargs hg revert
2011-06-01 19:54:41
User: yrcjaya
Functions: xargs
Tags: mercurial

Undo accidental file add to mercurial.

This command undo file adds to all recent adds

find ~ -type f -size +500M -exec ls -ls {} \; | sort -n
2013-11-17 13:13:14
User: marcanuy
Functions: find ls sort
Tags: size find

Find all files larger than 500M in home directory and print them ordered by size with full info about each file.

sudo apt-get install ufraw
2015-08-20 20:37:00
User: dnlcorrea
Functions: install sudo

Convert RAW files (eg. .CR2) to JPEGs, PNGs and whatnot.

ps gv [pid] | head -2
2009-02-12 05:04:55
User: ren
Functions: head ps

sh as:

#! /bin/sh

while [ 1 -ne 6 ]; do

pid=`ps -ef | grep -v "grep" | grep "trans_gzdy" | cut -c10-17`

ps gv $pid | head -2

sleep 1


check changes of RSS.

snmpwalk -v2c -c <community> -m ALL <HOST_IP> .
netstat -antu | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
2013-04-08 19:46:41
User: wejn
Functions: awk netstat sort uniq

Output contains also garbage (text parts from netstat's output) but it's good enough for quick check who's overloading your server.

while cat energy_now; do sleep 1; done |awk -v F=$(cat energy_full) -v C=60 'NR==1{P=B=$1;p=100/F} {d=$1-P; if(d!=0&&d*D<=0){D=d;n=1;A[0]=B=P}; if(n>0){r=g=($1-B)/n;if(n>C){r=($1-A[n%C])/C}}; A[n++%C]=P=$1; printf "%3d %+09.5f %+09.5f\n", p*$1, p*g, p*r}'
2015-09-19 15:45:40
User: sqweek
Functions: awk cat printf sleep

Needs to be run in a battery sysfs dir, eg. /sys/class/power_supply/BAT0 on my system.

Displays the battery's current charge and the rate per-second at which energy is {dis,}charging. All values are displayed as percentages of "full" charge.

The first column is the current charge. The second is the rate of change averaged over the entire lifetime of the command (or since the AC cable was {un,}plugged), and the third column is the rate of change averaged over the last minute (controlled by the C=60 variable passed to awk).

The sample output captures a scenario where I ran 'yes' in another terminal to max out a CPU. My battery was at 76% charge and you can see the energy drain starts to rise above 0.01% per-second as the cpu starts working and the fan kicks in etc. While idle it was more like 0.005% per-second.

I tried to use this to estimate the remaining battery life/time until fully charged, but found it to be pretty useless... As my battery gets more charged it starts to charge slower, which meant the estimate was always wrong. Not sure if that's common for batteries or not.

find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \;
2009-02-12 07:43:29
User: rbattu
Functions: find scp

U have to make key exchange in order to avoid continuous password prompt.