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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

Hide

Credits

Commands by depesz from sorted by
Terminal - Commands by depesz - 37 results
netstat -atn | perl -ane 'if ( $F[3] =~ /(\d+)$/ ) { $x{$1}=1 } END{ print( (grep {!$x{$_}} 32768..61000)[0] . "\n" )}'
set -x
find . -type f -print0 | xargs -0 perl -pi.save -e 'tr/A-Z/a-z/'
2010-11-25 13:55:34
User: depesz
Functions: find perl xargs
Tags: perl find regex
1

In this way it doesn't have problems with filenames with spaces.

dsniff -i any 'tcp port pop3'
2

dsniff is general purpose password sniffer, it handles *lots* of different protocols, but it also handles tcp-style expressions for limiting analyzed traffic - so I can limit it to work on pop3 only.

ps uw --ppid $PID
echo $RANDOM
2010-11-09 09:57:44
User: depesz
Functions: echo
Tags: random
7

works at least in bash. returns integer in range 0-32767. range is not as good, but for lots of cases it's good enough.

find /mountpoint -type f -iregex '.*\.\(doc\|xls\)'
2010-11-04 18:15:35
User: depesz
Functions: find
1

When using regex - there is no need to use -o and 2nd regex.

getent hosts google.com | awk '{print $1}'
2010-11-03 12:02:05
User: depesz
Functions: awk getent
3

has the benefit of being a bit more cross-platform.

dpkg -L iptables | perl -lne 'print if -f && -x'
DISPLAY=:0.0 import -window root /tmp/shot.png
2010-10-28 12:00:00
User: depesz
25

Of course it requires import command, from imagemagick tools, but it's simpler to type, and imagemagick is usefull anyway.

rename 's/ /-/g' *
2010-10-23 17:03:54
User: depesz
Functions: rename
2

As long as you have perl based rename. You can check:

=$ rename --help

Unknown option: help

Usage: rename [-v] [-n] [-f] perlexpr [filenames]

That's the good one.

for file in *.png; do mogrify -trim "$file"; done