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

Generate an XKCD #936 style 4 word password

Terminal - Generate an XKCD #936 style 4 word password
perl -F'\s+' -anE 'push @w,$F[1];END{$r.=splice @w,rand @w,1 for(1..4);say $r}' diceware.wordlist.asc
2011-08-24 18:50:16
User: zedlopez
Functions: perl
0
Generate an XKCD #936 style 4 word password

Alternatives

There are 11 alternatives - vote for the best!

Terminal - Alternatives
shuf -n4 /usr/share/dict/words | tr -d '\n'
2011-08-10 13:04:39
User: Strawp
Functions: tr
Tags: tr xkcd shuf
21

4 random words are better than one obfuscated word

http://xkcd.com/936/

shuf -n4 /usr/share/dict/words | sed -e ':a;N;$!ba;s/\n/ /g;s/'\''//g;s/\b\(.\)/\u\1/g;s/ //g'
2011-08-11 19:49:21
User: vasti
Functions: sed
Tags: sed regex xkcd shuf
1

This is what I came up to generate XKCD #936 style four-word password.

Since first letter of every word is capitalized it looks a bit more readable to my eyes.

Also strips single quotes.

And yes - regex is a bit of a kludge, but that's the bes i could think of.

echo $(grep "^[^']\{3,5\}$" /usr/share/dict/words|shuf -n4)
2011-08-23 21:15:18
User: j_melis
Functions: echo grep
Tags: awk xkcd
1

The improvement of this command over Strawp's original alternative is that you can specify the size of the words, in this particular case words between 3 and 5 character's long. It also excludes words that contain apostrophes, if you'd rather keep those words simply substitue [^'] for .

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
0

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.

shuf /usr/share/dict/words |grep "^[^']\{3,5\}$" |head -n4
2011-08-24 03:43:55
User: menachem
Functions: grep head
Tags: awk xkcd
0

This does the same thing that the command 'j_melis' submitted, but does it a lot quicker.

That command takes 43 seconds to complete on my system, while the command I submitted takes 6 seconds.

Know a better way?

If you can do better, submit your command here.

Your point of view

You must be signed in to comment.

Related sites and podcasts