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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 h3xx from sorted by
Terminal - Commands by h3xx - 20 results
tcpdump -w - |pv -bert >/dev/null
2011-12-14 00:24:02
User: h3xx
Functions: tcpdump

Real gurus don't need fancy tools like iftop or jnettop.

aspell -a <<< '<WORDS>'
cp --sparse=always <SRC> <DST>
2011-09-07 08:02:50
User: h3xx
Functions: cp

This causes cp to detect and omit large blocks of nulls. Sparse files are useful for implying a lot of disk space without actually having to write it all out.


You can use it in a pipe too:

dd if=/dev/zero bs=1M count=5 |cp --sparse=always /dev/stdin SPARSE_FILE
2011-08-28 23:48:29
User: h3xx

This is shorter and actually much faster than >/dev/null (see sample output for timings)

Plus, it looks like a disappointed face emoticon.

grep ^Dirty /proc/meminfo
2011-08-24 08:48:49
User: h3xx
Functions: grep

Ever ask yourself "How much data would be lost if I pressed the reset button?"

Scary, isn't it?

lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
2011-08-15 03:10:58
User: h3xx
Functions: find ls sort xargs

Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too.

On my Slackware box, this gets set upon login:

LS_OPTIONS='-F -b -T 0 --color=auto'


alias ls='/bin/ls $LS_OPTIONS'

which works great.

echo $(($(ulimit -u)-$(pgrep -u $USER|wc -l))
grep -2riP '\b(fuck|shit|bitch|tits|ass\b)' /usr/src/linux/
xargs -P 3 -n 1 <COMMAND> < <FILE_LIST>
2011-07-25 22:53:32
User: h3xx
Functions: xargs

For instance:

find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8

will encode all .wav files into FLAC in parallel.

Explanation of xargs flags:

-P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage].

-n [max-args]: Max number of arguments from the list to send to each invocation.

-0: Stdin is a null-terminated list.

I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

(trap 'true' ERR; exec <SEGFAULT_PRONE_PROGRAM>)
2011-07-25 02:30:52
User: h3xx
Functions: exec trap
Tags: trap script error

Crash Override, man!

Apparently the exec call tricks BASH into setting the output buffer size to 0 under the assumption that the system (or the calling shell) will handle the output buffering. trapping the ERR signal will stop the subshell from dying and sending the ERR signal to the main script--which will terminate immediately if it does--when the program fails.

The only problem is that the kernel will output a whole bunch of stack trace garbage directly to the console device once the process segfaults, so there's no way to prevent it from being output [that I know of].

xxd -p <<< <STRING>
read VAR1 VAR2 VAR3 <<< aa bb cc; echo $VAR2
jpegtran -optimize -outfile temp.jpg <JPEG> && mv temp.jpg "$_"
2011-07-24 08:55:46
User: h3xx
Functions: mv
Tags: jpeg

You can also save EXIF information by copying it to temp.jpg:

jpegtran -optimize -outfile temp.jpg <JPEG> && jhead -te temp.jpg "$_" && mv temp.jpg "$_"
aumix -v +5
2011-07-24 07:41:40
User: h3xx
Functions: aumix
Tags: alsa


aumix -v -5

Map these to key combinations in your window manager and who needs special buttons?

xrandr -s 0
2011-07-24 07:38:01
User: h3xx

This forces X back to its maximum resolution configured. To get a list, type `xrandr'.

mplayer -af volnorm=2:0.75 dvd://
2011-07-24 07:26:51
User: h3xx
Tags: mplayer volume

Works really well for playing DVDs, which have the volume turned way down for some reason. The `2' method is better IMHO because it will adjust to changing loud/soft parts.

If you want to add it to your ~/.mplayer/config:

# format: volnorm[=method:target]

# method:

# 1: use single sample (default)

# 2: multiple samples

# target:

# default is 0.25


gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_"
2011-07-24 05:51:47
User: h3xx
Functions: gpg shred
Tags: GPG shred

Make sure the file contents can't be retrieved if anyone gets ahold of your physical hard drive.

With hard drive partition:

gpg --default-recipient-self -o /path/to/encrypted_backup.gpg -e /dev/sdb1 && shred -z /dev/sdb1

WARNING/disclaimer: Be sure you... F&%k it--just don't try this.

mplayer -playlist <(find "$PWD" -type f)
2011-07-24 03:27:03
User: h3xx
Functions: find
Tags: mplayer fd

Skip forward and back using the < and > keys. Display the file title with I.

zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz
export GREP_OPTIONS='--color=auto'
2011-07-24 01:32:10
User: h3xx
Functions: export
Tags: color grep

This will affect all invocations of grep, even when it is called from inside a script.