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.


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:



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.




Commands using tr from sorted by
Terminal - Commands using tr - 269 results
export PATH=$PATH$(find "$PWD" -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort -u | tr -d '\n'); echo $PATH
2011-03-11 19:31:17
User: dexterhu
Functions: echo export find sort tr

(1) don't run twice, or the same folder will occur in $PATH.

(2) otherwise you need to start a new terminal

CLASSPATH=.; export CLASSPATH=$CLASSPATH$(find "$PWD" -name '*.jar' -type f -printf ':%p\n' | sort -u | tr -d '\n'); echo $CLASSPATH
env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 10
2011-02-22 17:09:44
User: aerickson
Functions: env head tr



fixes a problem with bad bytes in /dev/urandom on Mac OS X

tr -dc a-z0-9 </dev/urandom | tr 0-8 \ | tr 9 \\n | sed 's/^[ \t]*//' | fmt -u
echo -e "Terminal shortcut keys\n" && sed -e 's/\^/Ctrl+/g;s/M-/Shift+/g' <(stty -a 2>&1| sed -e 's/;/\n/g' | grep "\^" | tr -d ' ')
2011-02-10 17:38:05
User: cicatriz
Functions: echo grep sed stty tr

This command will give you a list of available keyboard shortcuts according to stty.

wget http://www.youtube.com/watch?v=dQw4w9WgXcQ -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/' | wget -i - -O surprise.flv
2011-01-25 04:19:06
User: Eno
Functions: sed tr wget

Nothing special required, just wget, sed & tr!

cat YOUR_FILE|tr -d '[:punct:]'|tr '[:upper:]' '[:lower:]'|tr -s ' ' '\n'|sort|uniq -c|sort -rn
find $(echo "$PATH" | tr ':' ' ') -name "*program*"
seq -w 50 | sort -R | head -6 |fmt|tr " " "-"
head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt && wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt -O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
/usr/bin/lynx -dump http://www.netins.net/dialup/tools/my_ip.shtml | grep -A2 "Your current IP Address is:" | tail -n1 | tr -d ' '|sed '/^$/d'| sed 's/^ *//g'
sitepass2() {salt="this_salt";pass=`echo -n "$@"`;for i in {1..500};do pass=`echo -n $pass$salt|sha512sum`;done;echo$pass|gzip -|strings -n 1|tr -d "[:space:]"|tr -s '[:print:]' |tr '!-~' 'P-~!-O'|rev|cut -b 2-15;history -d $(($HISTCMD-1));}
2010-12-09 08:42:24
User: Soubsoub
Functions: cut gzip strings tr
Tags: Security

This is a safest variation for "sitepass function" that includes a SALT over a long loop for sha512sum hash

tr "\n" " " < file
2010-12-08 16:13:54
User: randy909
Functions: tr

Even shorter. Stolen from comment posted by eightmillion.

echo `cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c64`
2010-12-06 21:04:57
User: Dereckson
Functions: echo head tr

The same command, but with a base64 filter, more forgiving for special characters than tr.

echo `cat /dev/urandom |tr -dc "[:alnum:]" | head -c64`
cat file | tr -d "\n"
2010-12-02 09:22:02
User: uzsolt
Functions: cat file tr

This command deletes the "newline" chars, so its output maybe unusable :)

cat file | tr "\n" " "
2010-12-02 09:21:02
User: uzsolt
Functions: cat file tr

It's works only when you replace '\n' to ONE character.

ps -eo args,%cpu | grep -m1 PROCESS | tr 'a-z-' ' ' | awk '{print $1}'
echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=' ') f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"
2010-11-24 23:49:21
User: unefunge
Functions: echo printf tr xargs

displays current time in "binary clock" format

(loosely) inspired by: http://www.thinkgeek.com/homeoffice/lights/59e0/



.... - 1st hour digit: 0

*..* - 2nd hour digit: 9 (8+1)

.*.. - 1st minutes digit: 4

*..* - 2nd minutes digit: 9 (8+1)

Prompt-command version:

PROMPT_COMMAND='echo "10 i 2 o $(date +"%H%M"|cut -b 1,2,3,4 --output-delimiter=" ") f"|dc|tac|xargs printf "%04d\n"|tr "01" ".*"'

mailq | grep MAILER-DAEMON | awk '{print $1}' | tr -d '*' | postsuper -d -
for i in ./*.$1; do mv "$i" `echo $i | tr ' ' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '-' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr -s '_' `; done
echo `lcg-infosites --vo lhcb ce | cut -f 1| grep [[:digit:]]| tr '\n' '+' |sed -e 's/\ //g' -e 's/+$//'`|bc -l
2010-11-10 15:06:00
User: kbat
Functions: bc cut echo grep sed tr

Of course, this command must be executed at a GRID User Interface

lhcb - name of your VO, substitute it with the one you are interested it.

od -N 4 -t uL -An /dev/random | tr -d " "
2010-11-09 07:57:16
User: hfs
Functions: od tr
Tags: random

Reads 4 bytes from the random device and formats them as unsigned integer between 0 and 2^32-1.

for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done
tr -cs A-Za-z '\n' | sort | uniq -ci
2010-10-20 04:12:58
Functions: sort tr uniq
Tags: sort uniq tr

Gives the same results as the command by putnamhill using nine less characters.