Hide

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.

Hide

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:

Hide

News

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

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,619 results
du --max-depth=1 | grep -v '\.\/\.'
grep -l bar *.log | xargs grep -l foo
2011-01-10 19:54:46
User: dlebauer
Functions: grep xargs
Tags: bash xargs grep
-1

Uses xargs to call the second grep with the first grep's results as arguments

fromdos <file>
2011-02-14 17:28:53
User: jbuitt
-1

requires the package tofrodos on Debian/Ubuntu:

sudo apt-get install tofrodos

for i in {1..40};do echo -n $i. $(date +%H:%M:%S):\ ; (time curl 'http://ya.ru/' &> /dev/null) 2>&1|grep real;sleep 1;done
2011-11-11 10:40:38
User: AntonyC
Functions: date echo grep sleep time
Tags: curl
-1

This uses curl to find out the access times of a web service

perl -pi -e 's/foo/bar/g' $(grep -l foo ./*)
2009-03-27 17:18:08
User: dopeman
Functions: grep perl
-1

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory.

uuid
2009-08-14 14:02:37
-1

http://en.wikipedia.org/wiki/Universally_Unique_Identifier

http://www.ossp.org/pkg/lib/uuid/

You'll first need to install the uuid package. Available immediately from apt in Ubuntu, Debian, or other myriad Debian variants. You could always compile it from source as well.

du -sh * | grep -v '\.\/\.'
while $i;do `notify-send -t 200 "You are awesome :)"`;sleep 60; done;
2011-02-14 18:49:38
User: pahnin
Functions: sleep
-1

sends notification msg within repeated intervals of time to notify-send ;)

Just for fun.

df | awk '{if ($2!=dspace) print "different"; dspace=$2;}'
find . | sort | awk 'NR%2==0' | xargs rm $1
2013-07-11 07:36:18
User: sucotronic
Functions: awk find rm sort xargs
-1

If you have a directory with lot of backups (full backups I mean), when it gets to some size, you could want to empty some space. With this command you'll remove half of the files. The command assumes that your backup files starts with YYYYMMDD or that they go some alphabetical order.

perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*)
2009-03-27 17:21:35
User: dopeman
Functions: grep perl
Tags: perl
-1

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory and any sub-directories.

curl http://my-ip.cc/host.txt
2011-09-01 00:28:49
User: samleb
-1

Additionally it may give your geolocation if it's known by hostip.info

for ff in directory; do numLines=`wc -l $ff`; numLines=$(echo $numLines | sed 's/ .*//g'); min=$(sort -nrk 1 $ff | tail -1); if [ $numLines -gt 100 ]; then echo $min >> minValues; fi;done;
man perlcheat | col -b > perlcheat.txt
host -t a dartsclink.com | sed 's/.*has address //'
du -sh `ls -p | grep /`
curl http://my-ip.cc/host.xml
2011-09-01 00:30:03
User: samleb
-1

XML version.

Additionally it may give your geolocation if it's known by hostip.info

cobbler repo add --name=CentOS-5.3-i386-updates --mirror=http://mirror3.mirror.garr.it/mirrors/CentOS/5.3/updates/i386/
2009-04-27 10:18:45
User: w00binda
Tags: cobbler
-1

Add a repo to cobbler. To download all the repository contents the command is:

cobbler reposync
cal -y
2009-09-02 12:57:23
User: andrepuel
Functions: cal
-1

Show today date on a yearly calendar.

netstat -lantp | grep -i establ | awk -F/ '{print $2}' | uniq | sort
2009-09-19 13:54:36
User: ktoso
Functions: awk grep netstat uniq
-1

Can be used to discover what programms create internet traffic. Skip the part after awk to get more details.

Has anyone an idea why the uniq doesn't work propperly here (see sample output)?

curl -s "http://www.google.com/ig/api?weather=New%20York" | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1|'
2010-02-08 23:06:48
User: matthewbauer
Functions: sed
-1

Will return temperature in Fahrenheit of a location (New York City in example).

Uses a Google API.

cat 1.tar.gz 2.tar.gz | tar zxvif -
2010-05-09 03:50:00
Functions: cat tar
-1

You don't need to create an intermediate file, just pipe the output directly to tar command and use stin as file (put a dash after the f flag).

function titlescroll { _X=0 _TITLEMSG=$1 _WIDTH=${2:-16} _TITLEMSG=`printf "%$((${#_TITLEMSG}+$_WIDTH))s" "$_TITLEMSG"` while `true` do _X=$(((_X+1)%${#_TITLEMSG})) xtitle "${_TITLEMSG:_X:_WIDTH}" done }
2010-01-12 20:48:46
User: romulusnr
-1

Usage:

titlescroll "message" <width>

Requires command "xtitle" or replace with:

echo -ne "\e]0;TEXT_HERE\007"
find ./ -name Thumbs.db -exec rm -rf '{}' +