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.

Universal configuration monitoring and system of record for IT.
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

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

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,182 results
find . -type d -execdir du -sh '{}' ';' | grep -E "[0-9]+K" | sed 's/^[0-9\.]\+K[\t ]\+//' | tr "\n" "\0" | xargs -0 rm -rf
echo Faltan `curl http://www.elproximoferiado.com.ar/index.php?country=AR -silent | grep contador | cut -f2 -d">" | cut -f1 -d"<"` dias para el proximo feriado
curl "http://api.twitter.com/1/statuses/user_timeline.xml?count=1&screen_name=barackobama" | egrep -w "<text>(.*)</text>" | sed -E "s/<\/?text>//g" | say
2012-02-27 18:46:33
User: beerdeaap
Functions: egrep sed
Tags: twitter osx say
-1

speaks out last twitter update using 'say'

ls -1 | while read file; do new_file=$(echo $file | sed s/\ /_/g); mv "$file" "$new_file"; done
perl -i -pe "s/old/new/g" *
2009-02-05 12:07:27
User: pandres
Functions: perl
-1

Replaces every ocurrence of 'old' for 'new' in all files specified. After the 'i' char you can put a '~' or whatever to create a backup file for each replaced with the name equal to the original plus character.

sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).in-addr.arpa domain name pointer\(.*\)\./\4.\3.\2.\1\5/' \ lookups.txt
2009-08-22 09:37:20
User: hemanth
Functions: sed
Tags: sed
-1

Reverse DNS lookups, from a file with list of IP's, here the file is called lookups.txt

git branch --contains <commit sha1 id> | sed -e 's/^[ *]*//'
wmctrl -i -a `wmctrl -l -x | gpicker -d "\n" -n "\n" - | awk '{print $1}'`
2010-08-30 02:19:43
User: Iany
Functions: awk
-1

Require wmctrl and gpicker and an EWMH/NetWM compatible X Window Manager

egrep '__NR_' /usr/include/asm/unistd_`getconf -a | awk '$1~/^WORD/{print $2}'`.h | sed -e 's/^#define __NR_//' | column -t
w3m -dump_head www.fiat.com | awk '/Date+/{print $6, $7}'
2009-06-08 00:06:01
User: m33600
Functions: awk
-1

w3m is a commanline web browser, full of options, I used -dump_head for less unnecessary page download.

With awk, I can retrieve dynamic changes in webpages in this very econnomical fashion

sort file1 file2 | uniq -d
2010-05-28 10:25:31
User: emacs
Functions: sort uniq
-1

print members both in file1 and file2

perl -p -i -e 's/.*\n//g if $.==2' ~/.ssh/known_hosts
find /Applications -type d -maxdepth 1 -exec sh -c 'echo "{}"; (plutil -convert xml1 -o - "{}/Contents/Info.plist" | xpath /dev/stdin "concat(\"v\", /plist/dict/string[preceding-sibling::key[1]=\"CFBundleShortVersionString\"]/node())" 2>/dev/null)' \;
2013-03-29 14:01:23
User: darkfader
Functions: find sh
Tags: osx
-1

Uses find, plutil and xpath.

Note: Some applications don't have proper information. system_profiler might be better to use.

It's a bit slow query.

Due to command length limit, I removed -name "*.app" and CFBundleName.

diff /path/to/localfile <(ssh user@host cat /path/to/remotefile)
2013-05-24 09:24:31
User: mc0e
Functions: cat diff ssh
-1

Or, if you have restricted access for sftp only, I think you can still do this:

diff /path/to/localfile <(scp user@host:/path/to/remotefile >(cat))
eyeD3 --add-image=coverart.jpg:FRONT_COVER musicfile.mp3
du -hs file-name
for jj in `seq -f "%02.0f" 1 12`; do rr=`ls *S04E$jj*.smi`; tt=`ls *S04E$jj*.avi`; mv "$rr" "${tt%.*}.smi"; done
2009-02-05 12:16:06
User: beila
Functions: mv
-1

Subtitles' file names contain S04E01, S04E02, ... S04E12 and end with ".smi".

Videos' file names contain S04E01, S04E02, ... S04E12 and end with ".avi".

You can change the patterns by changing `ls *S04E$jj*.smi` and `ls *S04E$jj*.avi` parts.

You can change the number of starting and ending file by changing `seq -f "%02.0f" 1 12` part.

TIMEUNIT=$(awk '/timescale/{print NR}' a)
cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}'
2009-11-28 03:31:41
Functions: awk
-1

don't have to be that complicated

find -type d -name ".svn" -print0 | xargs -0 rm -rf
2010-02-25 10:16:18
User: tuxilicious
Functions: find rm xargs
-1

man find: If no paths are given, the current directory is used. - Can anybody tell me why so many people are typing the dot?

groovy -e 'println URLEncoder.encode("Some text")'
mtr -c 50 -r example.com
2015-08-05 07:18:52
User: ohe
-1

mtr is a network utility that combines traceroute and ping utility

perl -ne '@a=split(/,/); $b=0; foreach $r (1..$#a){ $b+=$a[$r] } print "$a[0],$b\n"' -f file.csv
2015-09-04 21:05:56
User: miniker84
Functions: perl
-1

For all lines sum all columns following the first one and then print the first column plus the sum of all the other columns.

find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i
schedtool 1
2009-08-06 08:42:03
-1

Display information about the cores.

* sudo apt-get install schedtool