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





Commands using tr from sorted by
Terminal - Commands using tr - 284 results
dig @resolver1.opendns.com myip.opendns.com | grep ^myip.opendns.com | tr '\t' : | cut -d: -f5
cd ~/.msf4/loot && cat *mscache* | cut -d '"' -f 2,4 | sed s/\"/\:/g | tr -cd '\11\12\40-\176' | grep -v Username | cut -d : -f 1,2 | awk -F':' '{print $2,$1}' | sed 's/ /:/g' > final.dcc.hash
tr -dc '[:print:]' < <file>
2012-11-22 06:29:26
User: seb1245
Functions: tr
Tags: printing tr

tr has some predefined sets of characters that are more convenient to use than characters codes

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
2012-11-09 00:40:22
User: cnyg
Functions: cat fold head python tr

Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form.

tr -d '\r' < <input> > <output>
echo "your string here" | tr '\!-~' 'P-~\!-O'
2012-11-06 12:49:00
User: DevEd
Functions: echo tr

This command will encode a string using the ROT47 cipher.

java -jar app.jar -cp $(echo lib/*.jar | tr ' ' ':')
2012-10-29 12:51:46
User: xymor
Functions: echo tr
Tags: java cli

Lauching an app including jars in an adjacent lib folder to its classpath

tr -dc '[:graph:]' </dev/urandom | head -c30; echo
head -c7 /dev/urandom|base64|tr -d '='
tr -dc A-Za-z0-9_ < /dev/urandom | head -c 10 | xargs
echo $(</dev/urandom tr -dc 1-6 | head -c1)
echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr

Also shows files as they are found. Only works from a tty.

tcpdump -ntr NAME_OF_CAPTURED_FILE.pcap 'tcp[13] = 0x02 and dst port 80' | awk '{print $4}' | tr . ' ' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | awk ' {print $2 "\t" $1 }'
lsof -p `pidof pidgin` | awk '{ print $9 }'|egrep `hostname` | grep -o ">[^:]\+:" | tr -d ":>" | while read line; do host $line; done;
pbpaste | tr '\r\n' '\n' | tr '\r' '\n' | pbcopy
2012-07-31 10:50:14
User: adambrenecki
Functions: tr

Copying and pasting from Office documents open in Office:mac can dirty your files with Windows CRLF and (inexplicably) Classic Mac OS LF newlines, which can break some tools. This snippet replaces them with good ol' Unix LF newlines.

export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
tr -s ' '
2012-06-26 19:34:18
User: ankush108
Functions: tr
Tags: tr

Convert long list of ' ' to a single space. Compress space and other characters.

tr a-z A-Z < file.txt
for file in * ; do mv "$file" `echo "$file" | tr ' ' '_' | tr '[A-Z]' '[a-z]'`; done
2012-05-06 17:54:06
User: cengztr
Functions: file mv tr

All files in the directory will be renamed replacing every space in the filename by "_" (underline) and converting upper case characters to lower case characters.

e.g. Foo Bar.txt --> foo_bar.txt

printf "%$(tput cols)s\n"|tr ' ' '='
2012-04-21 23:26:55
Functions: printf tr

Use tput cols to find the width of the terminal and set it as the minimum field width.

dd if=/dev/zero bs=64K count=1 | tr "\0" "\377" > all_ones
2012-04-17 18:01:59
User: anduril462
Functions: dd tr

dd can be used with /dev/zero to easily create a file of all zero-bytes. Pipe that through tr and use octal conversions to change the byte values from zero to 0xff (octal 0377). You can replace 0377 with the byte of your choice. You can also use \\0 and \\377 instead of the quoted version.

cal | egrep -e '^ [0-9]|^[0-9]' | tr '\n' ' ' | awk '{print $NF}'
2012-04-16 11:58:09
User: gouverney
Functions: awk cal egrep tr

Returns last day of current month. Useful to implement a bash script backup based on a GFS strategy.

paste <(seq 7 | shuf | tr 1-7 A-G) <(seq 7 | shuf) | while read i j; do play -qn synth 1 pluck $i synth 1 pluck mix $2; done
dng(){ local a;a=$(sed '/'"$1"'/!d' /etc/hosts |sed '=;'"${2-1,$}"'!d'|sed '/ /!d');echo $a|tr '\040' '\n'|nl -bp'[0-9]$'|less -E;export dn=$(echo $a|sed 's,.* ,,');export ip=$(echo $a|sed 's, .*,,');echo \$dn=$dn;echo \$ip=$ip;}
2012-04-01 23:57:09
User: argv
Functions: echo export less nl sed tr

usage: dng BRE [selection]

default selection is the last match

DNS is ok, but although domainnames may be easier to remember than IP numbers, it still requires typing them out. This can be error-prone. Even more so than typing IPv4 numbers, depending on the domainname, its length and complexity.