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 matching random password from sorted by
Terminal - Commands matching random password - 56 results
TMPFILE="/tmp/$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM" && arecord -d 1 -t raw -f cd -q | base64 > $TMPFILE && pwgen -ys 12 12 -H $TMPFILE $@ && rm $TMPFILE
2014-06-09 16:28:41
User: juliohm
Functions: arecord cd rm

Generate a truly random password using noise from your microphone to seed the RNG. This will spit out 12 password with 12 characters each, but you can save this into a bash script and replace 'pwgen -ys 12 12' with 'pwgen $@' so you can pass any paramters to pwgen as you would normally do.

pwgen -CsyN 1 16
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
2009-02-17 23:36:24
User: TyIzaeL
Functions: cut dd rev

I know there are a lot of random password generators out there, but I wanted something that put out something besides hex. Set count equal to the number of bytes you want.

dd if=/dev/urandom count=200 bs=1 2>/dev/null | tr "\n" " " | sed 's/[^a-zA-Z0-9]//g' | cut -c-16
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q
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

jot 4 | awk '{ print "wc -l /usr/share/dict/words | awk '"'"'{ print \"echo $[ $RANDOM * $RANDOM % \" $1 \"]\" }'"'"' | bash | awk '"'"'{ print \"sed -n \" $1 \"p /usr/share/dict/words\" }'"'"' | bash" }' | bash | tr -d '\n' | sed 's/$/\n/'
2011-08-16 00:26:56
User: fathwad
Functions: awk bash sed tr
Tags: tr xkcd

So I use OSX and don't have the shuf command. This is what I could come up with.

This command assumes /usr/share/dict/words does not surpass 137,817,948 lines and line selection is NOT uniformly random.

openssl rand 6 -base64
2011-10-05 14:24:41
User: Le_Jax

just change 6 to 9 or 12 or more (multiple of 3) to have bigger password

false; while [ $? != 0 ]; do apg -c /dev/urandom -n1 -E oOlL10 | egrep '^[[:alnum:]]+$'; done
head -c 24 /dev/urandom | base64
2013-09-28 16:32:47
User: henix
Functions: head
Tags: random

Use less random number resources and less commands

echo $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10)
2013-11-07 21:51:38
User: santizo
Functions: echo head tr

Uses urandom and tr to generate a random password. Change the value of head -c## for the lenght of the password.

xxd -l 20 -c 20 -p /dev/urandom
2014-03-26 09:44:04
User: jt
Tags: password

Dumps 20 bytes from /dev/urandom and converts them to hex. -c and -p are needed to prevent splitting over lines.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
2014-04-07 10:07:22
User: opexxx
Functions: head tr

This snippet will produce an alpha-numeric 16 character password

python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*-_=+") for i in range(10)])'
2014-06-10 14:30:02
User: jouz
Functions: python

for i rang(10) = length of the password

random.choice("abcdefghijklmnopqrstuvwxyz...") = char allowed into the password

Thanks Python/Django FAQ's.

tr -dc '\x15-\x7e' < /dev/urandom| head -c 16 | paste
tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c10
2009-12-01 14:22:20
User: Phil
Functions: head tr

A slightly shorter version. Also doesn't put a return character at the end of the password

makepasswd --char=32
2010-09-29 06:01:32
User: zed

A more robust password creation utility

# Create passwords in batch

makepasswd --char=32 --count=10

# To learn more about the options you can use

man makepasswd
RANGE=`wc -l /usr/share/dict/words | sed 's/^\([0-9]*\) .*$/\1/'`; for i in {1..4}; do let "N = $RANDOM % $RANGE"; sed -n -e "${N}p" /usr/share/dict/words | tr -d '\n'; done; RANGE=100; let "N = $RANDOM % $RANGE"; echo $N
awk 'BEGIN {srand} /^[a-z]{4,8}$/ {w[i++]=$0} END {while (j++<4) print w[int(rand*i)]}' /usr/share/dict/words
2011-08-18 02:09:42
User: putnamhill
Functions: awk
Tags: awk xkcd

If you do not have shuf or an -R option in sort, you can fall back on awk. This provides maximum portability IMO. The command first collects words from the dictionary that match the criteria - in this case: lower case words with no punctuation that are 4 to 8 characters long. It then prints 4 random entries. I decided to print each word on a separate line to improve readability.

2011-10-13 14:46:03
User: evolix

Permit to generate a password for userPassword in ldap.

Use ?slappasswd -g? to generate a random passowrd.

dd if=/dev/urandom | tr -d -c [:print:] | tr -d " " | dd count=1 bs=20 2> /dev/null; echo
2013-03-01 22:42:29
User: Progent
Functions: dd tr

It will produce passwords with length of 20 printable characters within a reasonable time.

For shorter or longer passwords just change the 20 in bs=20 to something more convenient.

To create only alpha numeric passwords change [:print:] to [:alnum:]

$ apg -m 40 -a 1
2013-07-26 14:13:49
User: blz

apg generates several random passwords. It uses several password generation algorithms (currently two) and a built-in pseudo random number generator.

head -c $((<pw-lenght>-2)) /dev/urandom | uuencode -m - | sed -e '1d' -e '3d' | sed -e 's/=.*$//g'
2009-03-24 20:05:16
User: P17
Functions: head sed uuencode

Replace < pw-length > with the desired password-length.

The password-length is not always correct, but wayne...

tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | sed 1q
pwgen 30