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.

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

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

Tags

Hide

Functions

Commands using tr from sorted by
Terminal - Commands using tr - 274 results
tr '\0' '\377' < /dev/zero|dd count=$((<bytes>/512))
2011-04-05 14:26:02
User: cfy
Functions: dd tr
Tags: dd tr
4

the speed is about 500MB/s on my machine.

i think it's fast enough to output not too many bytes.

while a C program may output 1GB per sencond on my machine.

if the size is not the power of 512,you may change the bs and count in dd.

telnet towel.blinkenlights.nl 666 | sed "s/=== The BOFH Excuse Server ===//" | tr -d '\n' && echo
2011-03-31 05:50:57
User: hintss
Functions: sed telnet tr
Tags: telnet BOFH
4

Gets a BOFH excuse from the BOFH excuse server (towel.blinkenlights.nl port 666), and passes it through sed and tr to get rid of telnet connection stuff.

while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
2011-03-22 10:02:23
User: hons
Functions: awk cut echo grep sleep tr
15

Just a simple way without the need of additional tools. Of course, replace eth0 with your IF.

function rot13 { if [ -r $1 ]; then cat $1 | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; else echo $* | tr '[N-ZA-Mn-za-m5-90-4]' '[A-Za-z0-9]'; fi }
2011-03-18 09:59:41
User: twjolson
Functions: cat echo tr
Tags: Linux unix tr
-5

Will rot 13 whatever parameter follows 'rot13', whether it is a string or a file. Additionally, it will rot 5 each digit in a number

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

(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
0

Prepending

env LC_CTYPE=C

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
7

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
37

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
-4

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
7

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
-1

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
-1

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
9

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
4

displays current time in "binary clock" format

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

"Decoding":

8421

.... - 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 -