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,847 results
find . -type f | xargs ls -ltrhg
2010-05-28 01:23:53
User: emacs
Functions: find ls xargs
-1

find and normal files and list them sorting with modification time without group

l: with detailed information

t: sort with modification time

r: reverse order

h: show file's size in human-readable format, such as K(kilobytes), M(megabyes) etc.

g: do not show group

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
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")'
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

COPYFILE_DISABLE=true tar cvf newTarFile.tar Directory/
2010-07-01 09:36:48
User: alainkaa
Functions: tar
Tags: macosx
-1

Using the COPYFILE_DISABLE=true environment variable you can prevent tar from adding any ._-files to your .tar-file on Mac OS X.

dirname $(readlink -f ${BASH_SOURCE[0]})
for i in {001..999}; print $i
2009-02-16 23:03:53
User: karld
-1

zsh only

I always hated resorting to using $(seq -w 1 99) to pad numbers. zsh provides a shortcut that couldn't be more intuitive. It also works in reverse {99..01}