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.

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:



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!

Top Tags





Commands by bugmenot from sorted by
Terminal - Commands by bugmenot - 49 results
npm list -g --depth 0
awk '{ total += gsub(/yourstring/,"") } END { print total }' yourfile
2014-12-16 21:00:45
User: bugmenot
Functions: awk

Count how many times a pattern is present into a file. It can be one or more lines. No overlapping. It means searching for aa on aaa will output 1 not 2.

echo something | awk '{ total += gsub(/yourstring/,"") } END { print total }'
2014-12-16 20:58:42
User: bugmenot
Functions: awk echo

Count how many times a pattern is present into a stream. It can be one or more lines. No overlapping. It means searching for aa on aaa will output 1 not 2.

for i in {0..255} ; do (ping 192.168.1.$i -c 1 > /dev/null && echo "192.168.1.$i" & ) ; done
2014-01-26 18:31:34
User: bugmenot
Functions: echo ping

Pings all the hosts on in parallel, so it is very fast. Alive host IP addresses are echoed to stdout as pings are responded to.

find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
2013-09-28 15:44:32
User: bugmenot
Functions: find sed

Shows the OS X applications downloaded from App Store. Doesn't include manually added apps.

curl -s $1 | grep -o -i '<a href="//images.4chan.org/[^>]*>' | sed -r 's%.*"//([^"]*)".*%\1%' | xargs wget
2013-07-22 10:33:55
User: bugmenot
Functions: grep xargs

first grep all href images then sed the url part then wget

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

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.

cat somefile | tee >(openssl md5 > sum.md5) | bzip2 > somefile.bz2
copy /b part.1 + part.2 + part.n file.extension
cat list.txt | pax -wd > archive.tar
cat /dev/zero | pv -L 3m -Ss 100m > /dev/null
2012-12-15 10:17:52
User: bugmenot
Functions: cat

This example will close the pipe after transferring 100MB at a speed of 3MB per second.

lftp -u user,pass ftp://site.com -e 'pget -c -n 6 file'
2012-12-11 16:18:52
User: bugmenot
Functions: lftp

This is for files only, for directories 'mirror' has to be used.

for line in `wget --referer='http://500px.com/' --quiet -O- http://500px.com/popular | grep "from=popular" | sed -n 's/.*<img src="\([^"]*\)".*/\1/p' | sed s/"3.jpg"/"4.jpg"/ | sed s/"?t".*$//`; do wget -O $RANDOM.jpg --quiet "$line"; done
2012-12-07 16:14:36
User: bugmenot
Functions: grep sed

This command downloads the actual 20 most popular pictures from the website 500px. It uses a random name due to the fact the the pictures in 500px are stored with the same name.

UPDATED: doesn't work if no referrer is specified: --referer='http://500px.com/'

lftp -u user,pass ftp://site.com/ -e 'mirror -c --parallel=3 --use-pget-n=5 "Some folder"'
2012-11-24 11:29:48
User: bugmenot
Functions: lftp

It works best if you first login and then do the fetch:

lftp -u user,pass ftp://site.com/

mirror -c --parallel=3 --use-pget-n=5 "Some folder"

star -c -v -f myarchive.tar -no-dirslash list=list.txt
sed -e "s,/\+$,," -e "s,^/\+,," file.txt
2012-11-02 21:08:30
User: bugmenot
Functions: sed

There can be more than one trailing slash, all of them will be removed.

cat file.txt | grep -v /$ > newfile.txt
dd if=mybackup.ab bs=24 skip=1 | openssl zlib -d > mybackup.tar
dd.exe --progress if=\\.\Volume{0b1a0cbe-11da-11c0-ab53-003045c00008} of=pendrive.img
2012-10-13 08:25:48
User: bugmenot
Functions: dd

Blocksize (bs) is not mandatory. It's only needed when the count option is specified.

xterm +u8 -fn mtx -maximized -T "There is no spoon!" -e cmatrix -bxa -u 3 & sleep .1s && wmctrl -r :ACTIVE: -b add,fullscreen && transset-df -a &
2012-09-28 04:46:28
User: bugmenot
Functions: sleep
apt-get install cmatrix cmatrix-xfont wmctrl transset-df

Need to restart computer for mtx font to work

Commands while cmatrix is running:

1 - 9 = Change speed

SHIFT + 1 - 7 = change colors

Q = Quit

Tested in Ubuntu 10.04

find ./ -empty -type d -delete
find ./ -empty -type d -print
find ./ -maxdepth 1 -empty -type d -delete
find ./ -maxdepth 1 -empty -type d -print