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,620 results
netstat -an | grep 80 | wc -l
ffmpeg -i source.mpg -f s16le -acodec pcm_s16le audio.raw
2013-01-10 02:54:04
User: manuq
0

-i sets the source file

-f and -acodec both set the output to be raw audio, PCM signed 16-bit little endian

find /etc -type f -print0 | xargs -r0 grep --color '192.168.0.1'
2013-04-30 15:03:20
User: jakezp
Functions: find grep xargs
0

find ip address in all files in /etc directory. can be used to find any string in any directory really

cut -d, -f1 /var/opt/example/dumpfile.130610_subscriber.csv | cut -c3-5 | sort | uniq -c | sed -e 's/^ *//;/^$/d' | awk -F" " '{print $2 "," $1}' > SubsxPrefix.csv
2013-07-17 07:58:56
User: neomefistox
Functions: awk cut sed sort uniq
Tags: Linux UNIX
0

dumpfile is a CSV file, which its 1st field is a phone number in format CC+10 digits

Empty lines are deleted, before the output in format "prefix,ocurrences"

convert multi_layer.tif -compress jpg multi_page.pdf
2013-09-26 14:44:01
User: algol
0

Creates a PDF file where each page will be a layer from de original TIFF file.

You can apply many other filters and transformations.

convert multi_layer.tif -page a4 -compress jpg multi_page.pdf

To set the page size

convert multi_layer.tif -crop 590x790+20+30 -compress jpg multi_page.pdf

To include only a portion of the image (discard first horizontal 20 pixels and first vertical 30 pixels, include the next 590 horizontal and 790 vertical pixels)

convert multi_layer.tif -delete 1,3,5-10 -compress jpg multi_page.pdf

Discard mentioned layers

git log --pretty=oneline --abbrev-commit
pbpate | sort | pbcopy
'ls -1 *<pattern>* | while read file; do scp $file user@host:/path/; if [[ $? -eq 0 ]]; then rm $file; fi; done'
ffmpeg2theora input.avi
sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
2009-09-03 04:40:10
User: kulor
Functions: sudo
0

adding users to groups on OS X is not a straightforward process, you need to use the new in built in Directory Service command line utility...

/usr/bin/truss /usr/bin/date 2>&1 | nawk -F= '/^time\(\)/ {gsub(/ /,"",$2);print $2}'
for R in `svn log file:///path/repo | grep ^r | grep dude | cut -d' ' -f1 | cut -dr -f2`; do svn ps svn:log --revprop -r $R "`svn pg svn:log --revprop -r $R file:///path/repo; perl -e 'print ".\n";' | fromdos`" file:///path/repo; done
2011-03-24 08:29:15
User: theist
Functions: cut grep ps
Tags: svn
0

Let's supose some moron used some m$ shit to commit to a later svnsynced repo. On a svn sync all his message logs cause a svnsync: Error setting property 'log': this commands finds all its contributions and fix all his commit logs

apt-get remove $(dpkg -l | awk "/^ii linux-(image|headers)/ && ! /`uname -r`/ {print \$2}")
2011-10-09 13:58:47
User: _john
Functions: apt awk
0

since awk was already there one can use it instead of the 2 greps. might not be faster, but fast enough

ls -l =gcc
ettercap -i wlan0 -T -q -P dns_spoof -M ARP:remote // //
2011-12-25 15:41:09
User: f3bruary
Tags: ettercap
0

This command will enable dns spoofing through ettercap. The etter.dns config file must be set. The -i parameter defines the interface, e.g. eth0, eth1, wlan0...

ettercap -h for more info

Credit goes to xhabie-crew

echo `disklabel mfid1s4 | sed -n '$p' | awk '{print $2}'` / 1024 / 1024 | bc -l
qrencode -o contact.png ?`cat contact.vcs`?
2012-07-12 08:34:18
User: bash_vi
Tags: qr qrencode
0

Generates a qr Code from a textfile and saves the code as png. Works with any ASCII file (obviously)

grep --color=always -nr 'setLevel' --include=*py | less -SRqg
convert infile.png \( +clone -channel GB -evaluate set 0 +channel \) +append -region 50%x100% -channel R -evaluate set 0 +channel outfile.png
2013-04-30 20:46:02
User: bugmenot
Functions: set
0

Converts red-cyan 3D anaglyphs to side-by-side format viewable by crossing your eyes. Useful for people who don't have 3D glasses or prefer not to use one.

echo "q+werty%3D%2F%3B" | php -r "echo urldecode(file_get_contents('php://stdin'));"
2013-07-17 11:37:36
User: kartikssj
Functions: echo
Tags: urldecod PHP
0

Using PHP shell to URL decode a string.

perl -nle 'print length,"\t",$_ if length > 37' < /path/to/input/file
find . -name "*.html" -exec grep -l 'string' {} \;
2010-04-12 20:47:25
User: rexington
Functions: find grep
0

This will search for "string" in all files under the given path "." and provide a listing of the files with their relative locations.

echo Good $(i=`date +%H` ; if [ $i -lt 12 ] ; then echo morning ; else if [ $i -lt 15 ] ; then echo afternoon ; else echo evening ; fi ; fi)
2010-09-23 09:50:13
User: jyro
Functions: echo
Tags: date
0

Saves all the "cut" hacks

perl -le 'print time()'
svnradd() { for i in $1/*;do if [ -e "$i" ];then if [ -d "$i" ];then svn add $i;svnradd $i;else svn add $i;fi; fi;done }
2011-02-16 03:33:57
User: lkjoel
0

This will recursively add files/directories in SVN.

Usage:

svnradd yourfile

or

svnradd yourdirectory

then:

svn commit

Notice: It might not work properly, and not all files could get added.

Since there is a limit on characters, I couldn't add failure/success notices.

If you want failure/success notices, download Terminal Enhancements (http://tenhancements.tk/ )

It is included on Base Features