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

Makes you look busy

Terminal - Makes you look busy
alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
2010-03-09 21:48:41
User: busybee
Functions: alias awk find head sort vim wc
22
Makes you look busy

This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.

Alternatives

There are 5 alternatives - vote for the best!

Terminal - Alternatives
alias busy='rnd_file=$(find /usr/include -type f -size +5k | sort -R | head -n 1) && vim +$((RANDOM%$(wc -l $rnd_file | cut -f1 -d" "))) $rnd_file'
2011-10-16 00:05:59
User: frntn
Functions: alias cut find head sort vim wc
0

Enhancement for the 'busy' command originally posted by busybee : less chars, no escape issue, and most important it exclude small files ( opening a 5 lines file isn't that persuasive I think ;) )

This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim.

Know a better way?

If you can do better, submit your command here.

What others think

i like the idea :D

Comment by RanyAlbeg 233 weeks and 6 days ago

Fails here due to sort not knowing -R.

CentOS 5.3

sort (GNU coreutils) 5.97

Comment by DaveQB 233 weeks and 4 days ago

It always takes me to the last line because the braces in the awk statement aren't properly escaped for zsh by the doublequotes. The following works for me:

my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk '{print $1}'); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file
Comment by tremby 233 weeks and 4 days ago

Oops -- actually, in the alias statement as you wrote it it does in fact work fine. Interesting. My post above applied when using the body of the command alone on the commandline.

Comment by tremby 233 weeks and 4 days ago

Wow. That takes me back to the days when video games had "boss keys" that would show a fake spreadsheet or some such business-baloney. Of course, if you're at a command line, as this command assumes, I'm not quite sure what you'd want to hide from your boss... ASCII art Pr0n?

Comment by hackerb9 233 weeks and 3 days ago

you must add a backspace to escape the $ character in the awk argument and make it work:

alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
Comment by fsilveira 220 weeks and 6 days ago

you must add a backspace to escape the $ character in the awk argument and make it work:

alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print \$1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
Comment by fsilveira 220 weeks and 6 days ago

sorry, it works either way, but my fix makes the vim line jump work as expected by the author.

(is there a way to remove my first reply?)

Comment by fsilveira 220 weeks and 6 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts