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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

Hide

Credits

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 is 1 alternative - 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 281 weeks and 4 days ago

Fails here due to sort not knowing -R.

CentOS 5.3

sort (GNU coreutils) 5.97

Comment by DaveQB 281 weeks and 2 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 281 weeks and 2 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 281 weeks and 2 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 281 weeks and 1 day 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 268 weeks and 4 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 268 weeks and 4 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 268 weeks and 4 days ago

Your point of view

You must be signed in to comment.