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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 - 57 results
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
2009-02-16 00:39:28
User: jbcurtis
Functions: grep head strings tr

Find random strings within /dev/urandom. Using grep filter to just Alphanumeric characters, and then print the first 30 and remove all the line feeds.

shuf -n4 /usr/share/dict/words | tr -d '\n'
pwgen -Bs 10 1
2009-12-01 14:33:51

-B flag = don't include characters that can be confused for other characters (this helps when you give someone their password for the first time so they don't cause a lockout with, for example, denyhosts or fail2ban)

-s flag = make a "secure", or hard-to-crack password

-y flag = include special characters (not used in the example because so many people hate it -- however I recommend it)

"1 10" = output 1 password, make it 10 characters in length

For even more secure passwords please use the -y flag to include special characters like so:

pwgen -Bsy 10 1

output>> }&^Y?.>7Wu

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
2009-02-24 09:43:40
User: Blackbit
Functions: head tr

If you want a password length longer than 6, changing the -c6 to read -c8 will give you 8 random characters instead of 6. To end up with a line-feed, use this with echo:

# echo `< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6`

gpg --gen-random --armor 1 30
2011-07-20 15:32:49
User: atoponce
Functions: gpg

According to the gpg(1) manual:

--gen-random 0|1|2 count

Emit count random bytes of the given quality level 0, 1 or 2. If count is not given or zero, an endless sequence of random bytes will be emitted. If used with --armor the output will be base64 encoded. PLEASE, don't use this command unless you know what you are doing; it may remove precious entropy from the system!

If your entropy pool is critical for various operations on your system, then using this command is not recommended to generate a secure password. With that said, regenerating entropy is as simple as:

du -s /

This is a quick way to generate a strong, base64 encoded, secure password of arbitrary length, using your entropy pool (example above shows a 30-character long password).

cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
openssl rand -base64 6
2009-03-28 11:43:21
User: mpb

See: "man pwgen" for full details.

Some Linux distros may not have pwgen included in the base distribution

so you maye have to install it (eg in Mandriva Linux: "urpmi pwgen").

openssl rand -base64 <length>
</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""
2010-06-17 19:30:36
User: TexasDex
Functions: echo head tr

Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

pwgen 30 1
2011-07-24 19:43:48
User: sairon

The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible. Human-memorable passwords are never going to be as secure as completely completely random passwords. [from pwgen man page]

dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
2013-01-31 01:38:30
User: rodolfoap

This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it.


The file is composed of three parts:

a) The legible script (about 242 bytes)

b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242)

c) The actual filesystem

Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option.

PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :)

It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file.

The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables.

pwgen -Bnyc
2012-03-15 14:38:15
User: KoRoVaMiLK

These are my favourite switches on pwgen:

-B Don't include ambiguous characters in the password

-n Include at least one number in the password

-y Include at least one special symbol in the password

-c Include at least one capital letter in the password

It just works!

Add a number to set password length, add another to set how many password to output. Example:

pwgen -Bnyc 12 20

this will output 20 password of 12 chars length.

randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
2009-08-07 07:30:57
User: frozenfire
Functions: head tr

Generates password consisting of alphanumeric characters, defaults to 16 characters unless argument given.

date +%s | sha256sum | base64 | head -c <length>; echo
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

openssl rand -base64 12
2011-07-06 17:48:26
User: Mozai
Tags: password

Another password maker, for human-unfriendly passwords. '-base64' output will make sure it it can be typed on a keyboard, though the output string length will always be a multiple of 4.

echo -n $mypass | md5sum | awk {'print $1'}
2009-03-10 13:12:21
User: tororebelde
Functions: awk echo md5sum

This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script

cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16; echo
2014-02-05 15:04:07
User: yakovlev
Functions: cat env head tr

Feel free to put this in your ~/.profile:

random(){ cat /dev/urandom | env LC_CTYPE=C tr -dc $1 | head -c $2; echo; }

Then use it to generate passwords:

random [:alnum:] 16

Or DNA sequences:

random ACGT 256
strings /dev/urandom | tr -cd '[:alnum:]' | fold -w 30 | head -n 1
2014-12-11 06:21:51
User: atoponce
Functions: fold head strings tr

This command is similar to the alternate, except with head(1), you can pick as many passwords as you wish to generate by changing the number of lines you wish to preview.

genpass(){local i x y z h;h=${1:-8};x=({a..z} {A..Z} {0..9});for ((i=0;i<$h;i++));do y=${x[$((RANDOM%${#x[@]}))]};z=$z$y;done;echo $z ;}
2009-10-24 04:32:31
User: twfcc

make password randomly, default 8 chars, using bash3.X only, no external program.

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | sed 1q
perl -MDigest::SHA -e 'print substr( Digest::SHA::sha256_base64( time() ), 0, $ARGV[0] ) . "\n"' <length>
2010-04-30 21:45:46
User: udog
Functions: perl

Of course you will have to install Digest::SHA and perl before this will work :)

Maximum length is 43 for SHA256. If you need more, use SHA512 or the hexadecimal form: sha256_hex()

tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
while true; do curl -s http://sensiblepassword.com/?harder=1 | tail -n 15 | head -n 1 | sed 's;<br/>;;' | cut -c 5- | cb; sleep 1; done
2012-01-30 20:52:14
User: supervacuo
Functions: cut head sed sleep tail

Use the excellent sensiblepasswords.com to a generate random (yet easy-to-remember) password every second, and copy it to the clipboard. Useful for generating a list of passwords and pasting them into a spreadsheet.

This script uses "madebynathan"'s "cb" function (http://madebynathan.com/2011/10/04/a-nicer-way-to-use-xclip/); you could also replace "cb" with

xclip -selection c

Remove "while true; do" and "; done" to generate and copy only 1 password.