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



All commands from sorted by
Terminal - All commands - 12,333 results
dpkg-query -l| grep -v "ii " | grep "rc " | awk '{print $2" "}' | tr -d "\n" | xargs aptitude purge -y
2009-04-28 19:25:53
User: thepicard
Functions: awk grep tr xargs

This will, for an application that has already been removed but had its configuration left behind, purge that configuration from the system. To test it out first, you can remove the last -y, and it will show you what it will purge without actually doing it. I mean it never hurts to check first, "just in case." ;)

s(){ sed 's/./\n\0/g'<<<$1|sort;};cmp -s <(s foobar) <(s farboo)||echo -n "not ";echo anagram
2011-02-17 12:42:45
User: flatcap
Functions: cmp echo sed

Are the two strings anagrams of one another?

sed splits up the strings into one character per line

the result is sorted

cmp compares the results

Note: This is not pretty. I just wanted to see if I could do it in bash.

Note: It uses fewer characters than the perl version :-)

ls -alt /directory/ | awk '{ print $6 " " $7 " -- " $9 }'
tmpfs(){ cd /;for i in $@;do tar czvf /tmp/$i $i;mount -t tmpfs tmpfs /$i;tar xvzf /tmp/$i;cd ~ ;}# usage: tmpfs etc var
ps h -o pid,command | grep 'TEXT' | sed 's/^ \+//' | cut -d ' ' -f 1 | xargs -n 1 kill
col1(){ case $# in 0)echo col1 col-length;;*) sed 's/\(.\{'"$1"'\}\)\(.*\)/\1/' esac;}
2011-12-30 23:35:29
User: argv
Functions: sed

for small output only

example usage:

jobs -l |col1 72

function duf { du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done; }
sudo pmset -a hibernatemode 1
ps ux|grep <process name>|awk '{print $2}'|xargs -n 1 kill
cat .ssh/id_rsa.pub | ssh [email protected] "cat >>.ssh/authorized_keys2"
trap '' 1 2 20 24(signal number)
tail -n 20 ~/Library/Logs/FileSyncAgent.log
2009-02-19 05:05:21
User: sacrilicious
Functions: tail

tail would be considered dull, but pair this with being able to push out unix commands over ARD, and life gets easier. (Same can be said for my TimeMachine scrape command, http://xrl.us/begrzb)

find directory -maxdepth 1 -iname "*" | awk 'NR >= 2'
2014-04-01 00:09:12
User: chilicuil
Functions: awk find

find . -maxdepth 1 -iname ".*" | awk 'NR >= 2'

Can be used to list only dotfiles without . nor ..

(cd /bin; set -- *; x=$((1+($RANDOM % $#))); man ${!x})
2012-02-10 06:24:20
User: f4m8

Very similar but no use of `tr` for

function liner() {

local num_lines=${1:-42}

local line=$(printf %${num_lines}s)

echo ${line// /#}


v () { echo "$@"; "$@"; }
2011-10-13 11:33:19
User: hfs
Functions: echo

You can use this in shell scripts to show which commands are actually run. Just prepend every "critical line" with "v˽".


echo "Let me create a directory for you"

v mkdir $TMP/new

In scripts this can be more useful than "set -x", because that can be very verbose with variable assignments etc.

Another nice use is if you prepend every "critical" command with "v", then you can test your script by commenting out the actual execution.

renice -20 -g 2874 (2784 found with ps -Aj)
iptables -L -n -v
mkpasswd() { head -c $(($1)) /dev/urandom | uuencode - | sed -n 's/.//;2s/\(.\{'$1'\}\).*/\1/p' ;}
2009-11-19 14:27:52
User: taliver
Functions: head sed uuencode

This uses urandom to produce a random password. The random values are uuencoded to ensure only printable characters. This only works for a number of characters between 1 and 60.

for /f "delims==" %a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%a"
2010-01-18 20:56:00
User: vutcovici
Functions: dir echo

This command defragment the SQLite databases found in the home folder of the current Windows user.

This is usefull to speed up Firefox startup.

The executable sqlite3.exe must be located in PATH or in the current folder.

In a script use:

for /f "delims==" %%a in (' dir "%USERPROFILE%\*.sqlite" /s/b ') do echo vacuum;|"sqlite3.exe" "%%a"
alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe'
2009-11-19 16:38:51
User: taliver
Functions: alias gcc

This is a quick hack to make a gcc caller. Since it runs with gcc instead of tcc, it's a bit more trustworthy as far as the final answers of things go.

mkdir `date | sed 's/[: ]/_/g'`
2009-04-29 21:28:45
User: copremesis
Functions: mkdir sed

use today's time stamp to make a unique directory for today or an hour ago ...

echo -e "HEAD / HTTP/1.1\nHost: slashdot.org\n\n" | nc slashdot.org 80 | head -n5 | tail -1 | cut -f2 -d-
gst123 -z **/*
2010-05-18 13:45:41
User: eolo999
Tags: music zsh gst123

Depends on zsh and gst123 ( http://space.twc.de/~stefan/gst123.php )

cd in_your_music_root_folder and then issue the command

for i in $(tar -tf <file.tar.gz>); do rm $i; done;
2009-07-06 19:57:23
User: din7
Functions: rm tar

Remove annoying improperly packaged files that untar into the incorrect directory.

Example, When you untar and it extracts hundreds of files into the current directory.... bleh.