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,857 results
tshark -r data.pcap -zio,phs
xdg-mime default firefox.desktop x-scheme-handler/http
2011-12-28 16:36:27
User: natestar13
0

A universal way to configure your web browser. Note, you'll also need to set "x-scheme-handler/https" and "text/html" for https links and html files, respectively.

repoquery --whatrequires --installed --recursive packagename
2012-09-06 18:20:05
User: eddieb
Tags: yum
0

'yum deplist XXX' provides a list of packages that XXX depends on.

This command provides a list of packages that depend upon XXX (package reverse dependencies)

tr -d '\r' < <input> > <output>
lftp -c "pget -n 10 http://example.com/foo.bar"
nmon -f -T -^ -s 15 -c 12
2013-07-22 08:32:48
User: vidya99343
0

NMON Data collector , DQME

log on to appma569 as root

cd /tmp

nmon -f -T -^ -s 15 -c 12

du -ah | sort -hr | head -n50 | cat -n
svn status | awk -F" " '{ for (i=2; i<=NF; i++) print "ls -ld \""$i"\""}' | sh
2014-07-09 09:41:24
User: kln0thing
Functions: awk
Tags: svn awk ls
0

The AWK part of the code will "collate" the fields from 2nd to Nth field (this is to handle any svn directories that may have spaces in them - typical when working with code that is interchangeably used with windows environment - for example, documentation teams) - the output is passed to "ls -ld" - the -d option to ls will tell ls to handle directories itself, rather than do ls on the directory. The '-p' option is just for pretty printing directories, links and executables (for added readability).

Finally, the entire "constructed" command will be passed onto sh for shell execution.

cat -A
2009-02-06 02:37:51
User: mkc
Functions: cat
0

This is priceless for discovering otherwise invisible characters in files. Like, for example, that stray Control-M at the end of the initial hash bang line in your script, which causes it to generate a mysterious error even though it looks fine.

('od' is the last word, of course, but for many purposes it's much harder to read.)

mencoder -sub heading.ssa -subpos 0 -subfont-text-scale 4 -utf8 -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mjpeg -vf scale=320:-2,expand=:240:::1 -o output.avi input.flv
2009-09-21 11:56:55
User: ivalladt
0

Create subtitle file heading.ssa with just one entry for the entire video duration. Command line sets that entry's text on top of the video as text watermark. If text is an URL works nice for sending people back to your site from a YouTube clip. Output file is lossless encoded and suitable for further processing. Subtitle file can be a URL so it's saved remotely.

perl -e '$i=0;while($i<10){open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http://www.google.com/search?q=site:g33kinfo.com&hl=en&start=$i&sa=N},$i+=10}'|grep '\/\/g33kinfo.com\/'
2009-10-16 12:20:17
User: op4
Functions: grep perl xargs
Tags: web browser
0

not my cmd... found on the web

geoiplookup www.commandlinefu.com
2009-11-15 11:56:19
User: Sunng
0

geoip from maxmind

try to get the small utility via:

apt-get install geoip

dc -e '10 [q]sq[dd1=q1-lxx*]dsxxp'
2011-02-16 19:00:21
User: mwgamera
Tags: math factorial
0

More readable version of factorial calculation using standard desktop calculator instead of bc.

tshark -r data.pcap -R "ip.src==192.168.1.2" -T fields -e "ip.dst" |sort |uniq -c
rgrep <searchterm> *
find . -iname ".svn" | xargs rm -r $1
tar zcf - foo | gpg -c --cipher-algo aes256 -o foo.tgz.gpg
2013-03-13 09:44:39
User: skkzsh
Functions: gpg tar
0

Decrypt with:

gpg -o- foo.tgz.gpg | tar zxvf -
svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{count[$2]++}END{for(j in count) print count[j] "\t" j}' | sort -rn
2013-05-03 01:45:12
User: kurzum
Functions: awk egrep ls sort xargs
Tags: svn count
0

This one has a better performance, as it is a one pass count with awk. For this script it might not matter, but for others it is a good optiomization.

find /logs -ls -xdev | sort -nrk 7 | head -10
find ./ -type f -size +500k -exec ls -1Ash {} \; | sort -hr | cat -n
2013-10-01 10:32:28
User: rgregor
Functions: cat find ls sort
0

"find ./ ..." could be replaced with "find $PWD ..." to display absolute path instead of relative path.

finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}
2013-12-30 07:47:41
User: lowjax
Functions: awk echo return sed
0

Pass the files path to finfo(), can be unix path, dos path, relative or absolute. The file is converted into an absolute nix path, then checked to see if it is in-fact a regular/existing file. Then converted into an absolute windows path and sent to "wmic". Then magic, you have windows file details right in the terminal. Uses: cygwin, cygpath, sed, and awk. Needs Windows WMI "wmic.exe" to be operational. The output is corrected for easy...

finfo notepad.exe finfo "C:\windows\system32\notepad.exe" finfo /cygdrive/c/Windows/System32/notepad.exe finfo "/cygdrive/c/Program Files/notepad.exe" finfo ../notepad.exe
while true; do read i; echo $[$i]; done
2009-02-18 23:13:09
User: mulad
Functions: echo read
0

The $[...] block in bash and zsh will let you do math.

echo $[6*7]

This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.

geoip () { curl -s "http://www.geoiptool.com/?IP=$1" | html2text | egrep --color 'City:|IP Address:|Country:' }
2009-11-15 17:59:23
User: wizel
Functions: egrep
0

If used without arguments, returns own IP info.

If used with argument, returns info about the parsed argument.

webattery
In vim: q: && v[cursor movement]y && [paste/edit/save to /tmp/tmp.vim] && move to window to modify && :so /tmp/tmp.vim
2010-05-12 03:03:40
User: tmsh
0

It's actually really helpful if you've done a lot of replaces in say a header file, and now you want to replace the same text in the source code file.