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 sed from sorted by
Terminal - Commands tagged sed - 320 results
git for-each-ref --sort='-authordate' --format='%(refname)%09%(authordate)' refs/heads | sed -e 's-refs/heads/--'
source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )
2012-09-21 13:30:37
User: fishdaemon
Functions: egrep sed

Use meaningful exit codes

change "source" to "cat" to view output instead of assigning

sed 1d foo.txt
cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp
2012-09-13 20:57:40
User: kaushalmehra
Functions: cp rm sed
Tags: sed unix

sed '$ d' foo.txt.tmp

...deletes last line from the file

sed -n -e "/^\[/h; /priority *=/{ G; s/\n/ /; s/ity=/ity = /; p }" /etc/yum.repos.d/*.repo | sort -k3n
2012-09-06 00:09:09
User: eddieb
Functions: sed sort

This probably only works without modifications in RHEL/CentOS/Fedora.

for i in /var/spool/cron/tabs/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
2012-07-12 08:07:20
User: harpo
Functions: echo sed

This is flatcaps tweaked command to make it work on SLES 11.2

for i in /var/spool/cron/*; do echo ${i##*/}; sed 's/^/\t/' $i; echo; done
gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
2012-05-31 17:14:17
User: shr386
Functions: python

(1) required: python-googl ( install by: pip install python-googl )

(2) get from google API console https://code.google.com/apis/console/

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
mysqlbinlog <logfiles> | grep exec | grep end_log_pos | grep -v exec_time=0 | sed 's/^\(.*exec_time=\([0-9]\+\).*\)/\2 - \1 /' | sort -n
2012-05-30 09:38:02
User: theist
Functions: exec grep sed sort

Shows sorted by query time, the headers of mysqlbinlog entries. Then is easy to locate the heavier events on the raw log dump

iotop -a -p $(sed 's, , -p ,g' <<<`pgrep "_raid|_resync|jbd2"`)
2012-05-17 19:45:02
User: AskApache
Functions: sed

Shows the IO of the raid sync

echo `disklabel mfid1s4 | sed -n '$p' | awk '{print $2}'` / 1024 / 1024 | bc -l
gg(){ lynx -dump http://www.google.com/search?q=$@ | sed '/[0-9]*\..http:\/\/www.google.com\/search?q=related:/!d;s/...[0-9]*\..http:\/\/www.google.com\/search?q=related://;s/&hl=//';}
2012-04-21 03:31:26
User: chon8a
Functions: sed
Tags: sed lynx google

Get the first 10 google results form a querry, but showing only the urls from the results.

Use + to search diferent terms, ex: commandlinefu+google .

git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
2012-04-15 20:48:46
User: brockangelo
Functions: awk grep sed xargs

Written for Mac OSX. When you are working in a project and want to open it on Github.com, just type "gh" and your default browser will open with the repo you are in. Works for submodules, and repo's that you don't own.

You'll need to copy / paste this command into a gh.sh file, then create an alias in your bash or zsh profile to the gh.sh script. Detailed instructions here if you still need help:


for k in $(git branch | sed /\*/d); do echo "$(git log -1 --pretty=format:"%ct" $k) $k"; done | sort -r | awk '{print $2}'
2012-04-07 11:19:00
User: dahuie
Functions: awk echo sed sort
Tags: bash git sed awk

Simpler and without all of the coloring gimmicks. This just returns a list of branches with the most recent first. This should be useful for cleaning your remotes.

sed G input.txt | cat -s
sed -i 's/$/\r/' file
2012-02-23 08:34:30
User: evolix
Functions: sed

This permit to convert an UNIX file to DOS file.

You can use it in a loop to convert multiple files, like :

for i in *.bat; do sed -i 's/$/\r/' $i; done

cmdfu(){ local t=~/cmdfu;echo -e "\n# $1 {{{1">>$t;curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext"|sed '1,2d;s/^#.*/& {{{2/g'>$t;vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;rm $t; }
2012-02-21 05:43:16
User: AskApache
Functions: echo rm sed vim

Here is the full function (got trunctated), which is much better and works for multiple queries.

function cmdfu () {

local t=~/cmdfu;

until [[ -z $1 ]]; do

echo -e "\n# $1 {{{1" >> $t;

curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext" | sed '1,2d;s/^#.*/& {{{2/g' | tee -a $t > $t.c;

sed -i "s/^# $1 {/# $1 - `grep -c '^#' $t.c` {/" $t;



vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;

rm $t $t.c


Searches commandlinefu for single/multiple queries and displays syntax-highlighted, folded, and numbered results in vim.

sed -e 's/[;|][[:space:]]*/\n/g' .bash_history | cut --delimiter=' ' --fields=1 | sort | uniq --count | sort --numeric-sort --reverse | head --lines=20
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 .

print "$(lsvg -Lo |xargs lsvg -L|grep "TOTAL PPs"|awk -F"(" '{print$2}'|sed -e "s/)//g" -e "s/megabytes/+/g"|xargs|sed -e "s/^/(/g" -e "s/+$/)\/1000/g"|bc ) GB"
2012-02-03 13:58:41

Not figured by me, but a colleague of mine.

See the total amount of data on an AIX machine.

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).

sed -re '/^#/d ; s/#.*$// ; /^\s*$/d'
2012-02-02 18:12:52
User: Zulu
Functions: sed
Tags: sed

Use it with cat and '|' for know what is used in a conf file.

For example cat /etc/squid/squid.conf | sed -re '/^#/d ; s/#.*$// ; /^\s$/d' :

Show you what you use in your file conf.

It removes all comments and empty lines.

Empty lines are lines with nothing, a tab, or a space.

sed -i <file> -re '<start>,<end>d'