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
php -r 'echo json_encode( unserialize( file_get_contents( "php://stdin" ) ) );'
pssh -h RemoteHosts.txt -P -I < ~/LocalScript.sh
2014-07-14 16:02:12
User: zlemini
1

Runs a local script over ssh assuming ssh keys are in place.

-P argument prints results to stdout.

# Uses - https://code.google.com/p/parallel-ssh/

postqueue -p | grep -A 1 "over quota" | grep @ | sort | uniq | tr --delete ' '
hdparm -S5 /dev/sda
hdparm -y /dev/sda
find . -name "*.php" -exec php -l {} \; | grep found
2014-07-11 14:17:34
User: azizsaleh
Functions: find grep
0

Same but will only returns the invalid file (great when emailing the list to the team).

tail -f *.log | grep --color=always '|==>.+<=='
2014-07-11 07:47:27
User: danimath
Functions: grep tail
Tags: grep tail -f
0

This shows the the filenames of tail output in color. Helpful if you have many log files to tail

ssh -X user@host 'DISPLAY=:0 notify-send "TEST MESSAGE."'
awk '/text to grep/{print \$1}' logs... | sort -n | uniq -c | sort -rn | head -n 100
2014-07-10 20:36:02
User: impinball
Functions: awk head sort uniq
Tags: Linux sh
0

Accepts multiple files via logs.... Substitute "text to grep" for your search string.

If you want to alias this, you could do something like this:

alias parse-logs='awk "/$1/{print \$1}" ${@[@]:1} | sort -n | uniq -c | sort -rn | head -n 100'
find . -type f -iname '*.flac' | while read i; do mv -- "$i" "$i.tmp"; gst-launch filesrc location="$i.tmp" ! flacdec ! flacenc quality=8 ! filesink location="${i%.tmp}"; rm -- "$i.tmp"; done
2014-07-10 19:21:22
User: qdrizh
Functions: find mv read rm
0

Sometimes I get FLAC files that RhythmBox can't play but VLC can. So I re-encode them using GStreamer at highest compression.

translate () {lang="ru"; text=`echo $* | sed 's/ /%20/g'`; curl -s -A "Mozilla/5.0" "http://translate.google.com/translate_a/t?client=t&text=$text&sl=auto&tl=$lang" | sed 's/\[\[\[\"//' | cut -d \" -f 1}
2014-07-10 18:26:34
User: 2b
Functions: cut sed
0

Change lang from ru to something else.

Curl version - Mac OS etc, any system w/o wget.

musica nel cuore
2014-07-10 08:09:19
User: umbjmix
0

musica nel cuore dove c'? musica note di emozioni

/^........ \([0-7a-f][0-9a-f] *\)*[89a-f][0-9a-f]
find . |xargs grep '<html\|<body\|<table' |sed '/~/d;s/:.*//' |sed 's/.*/mv & &.html/' |uniq >run.sh; sh run.sh
git log --name-status --oneline --all | grep -P "^[A|M|D]\s" | awk '{print $2}' | sort | uniq
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.

awk '/text to grep/{print $1}' "log" | sort -n | uniq -c | sort -rn | head -n 100
2014-07-09 08:48:06
User: kln0thing
Functions: awk head sort uniq
0

Original command: cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100

This is a waste of multiple cats and greps, esp when awk is being used

grep -n "arrname\[[[:digit:]]\+\]" filename
2014-07-09 08:02:01
User: sleepy_11
Functions: grep
0

Just want to show the "+" usage in the grep command. And if using egrep, thing would be a little bit easier:

grep -n "arrname\[[[:digit:]]+\]" filename

cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100
pdfjam --clip true --trim '10mm 11cm 22pts 0' m.pdf
2014-07-08 10:57:54
User: qdrizh
Functions: true
0

This will crop each page of the PDF by 10mm left, 11cm bottom, 22pts right, and nothing from the top.

puppet config print modulepath
nmap -sP 192.168.1.*
2014-07-08 08:39:14
User: narven
0

you need to have nmap installed

sudo apt-get install nmap -y

sudo yum install nmap -y

dir=${PWD##*/}; rename "s/`ls -b1 | head -n1 | sed 's/.\{4\}$//'`/$dir/" -v *
2014-07-08 03:20:04
User: codycook
Functions: dir rename
0

I use this on Debian to rename files that exist in directories but do not have the year in the file name. The directory has the year but the files inside don't.

How I explain how this runs:

The dir variable grabs the name of the folder.

Using rename, substitute the name of the first file and remove the extension, then rename it to the directory name.

To test this before you run it, change -v to -vn.

xclip -o -selection clipboard | sort | xclip -i -selection clipboard
2014-07-07 19:04:02
User: gumnos
Functions: sort
1

Does the same thing in environments where you have "xclip" instead of "pbpaste"/"pbpate" and "pbcopy".

pbpate | sort | pbcopy