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

Commands by robinsonaarond from sorted by
Terminal - Commands by robinsonaarond - 10 results
rpm -q --queryformat="%{NAME}: %{OPTFLAGS}\n" <rpm>
2012-12-05 22:18:03
Functions: rpm
1

\n Separates out the architectures on different lines.

num_lines=${1:-42}
2012-02-09 17:31:33
4

I used it for this function, which prints hashes:

function liner {

num_lines=${1:-42}

echo

printf %${num_lines}s|tr " " "#"

echo

}

Note the colon-dash, instead of the usual colon-equals.

ps -p $$
2012-02-09 17:27:45
Functions: ps
4

works as well as echo $0, but also prints process id, which pts you're using. echo $SHELL doesn't always get updated when changing shells, so this is a better solution than that. Just one more variation on a theme.

myhex=$(printf '%02X' ${myip//./ };)
2011-11-30 15:12:28
Functions: printf
Tags: IP hex printf octet
2

Converts IP octets to hex using printf command. Useful for generating pxeboot aliases in the pxelinux.cfg folder.

ls ${my_dir:=/home}
2011-11-30 15:06:51
Functions: ls
2

Will use variable value (for variable $my_dir, in this case), an assign a default value if there is none.

[ $1 ] && my_dir=$1
2011-11-30 15:02:20
0

If Argument $1 is supplied, assign it to variable. Otherwise continue on.

script -f /tmp/foo; tail -f /tmp/foo
2011-11-22 15:16:08
Functions: script tail
Tags: script tail -f
2

script -f /tmp/foo will place all output of the terminal, including carriage returns, to a file. This file can be tail dash-eff'ed by one or more other terminals to display the information of the main terminal. Good way to share one's screen on short notice.

Note: This produces a very accurate output, but that includes depending on the size of your terminal to be the same. You can clear screens or even resize the terminal for others using this function; I use it in conjunction with the "mid" command in my list.

chflags nohidden ~/Library
2011-11-01 19:59:44
0

Adds/Removes the hidden flag on a file or folder, making it invisible in the Finder.

alias cls='printf %b '\''\033c'\'''
2011-11-01 14:31:30
Functions: alias
0

Syntax outside of an alias would be printf %b \\033c. This clears the screen and removes scrollback. Works on gnome-terminal and the XFCE's Terminal, and XTerm. It does clear the screen in Konsole and the Mac Terminal, but does not clear scrollback.

alias mid='printf "\e[8;24;80;t"'
2011-11-01 14:25:45
Functions: alias
0

Uses printf command to resize terminal.

So far, this is tested to NOT work in Konsole. Works with Mac Terminal, XFCE Terminal, XTerm, gnome-terminal.