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.

Universal configuration monitoring and system of record for IT.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

shell function to underline a given string.

Terminal - shell function to underline a given string.
underline() { echo $1; for (( i=0; $i<${#1}; i=$i+1)); do printf "${2:-=}"; done; printf "\n"; }
2010-02-26 05:46:49
User: bartonski
Functions: echo printf
shell function to underline a given string.

underline() will print $1, followed by a series of '=' characters the width of $1. An optional second argument can be used to replace '=' with a given character.

This function is useful for breaking lots of data emitted in a for loop into sections which are easier to parse visually. Let's say that 'xxxx' is a very common pattern occurring in a group of CSV files.

You could run

grep xxxx *.csv

This would print the name of each csv file before each matching line, but the output would be hard to parse visually.

for i in *.csv; do printf "\n"; underline $i; grep "xxxx" $i; done

Will break the output into sections separated by the name of the file, underlined.


There are 2 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

underline() { echo $1; echo "${1//?/${2:-=}}";}


underline() { echo -e "$1\n${1//?/${2:-=}}";}
Comment by mitry 353 weeks and 2 days ago

Nice. I actually thought of this, but couldn't get the substitution to work (now that I re-read the man page, I see that I missed 'If pattern begins with /, all matches of pattern are replaced with string'. I got flummoxed when I found that bash wasn't using a regex match, and stopped reading the man page carefully).

I thought I might be able to shave off an extra character by using

underline() { printf "$1\n${1//?/${2:-=}}";}

but this doesn't put a newline after the underline... ah. I see... that's 'echo -e' which interprets '\n' not 'echo -n' which removes the trailing new line. Thus I could use

underline() { printf "$1\n${1//?/${2:-=}}\n";}

but I'd be a stroke over par.

Comment by bartonski 353 weeks and 2 days ago

or using escape sequences

underline() { echo -e "\E[4m$1\E[0m" }

you can colour it too then...

Comment by quigybo 353 weeks and 1 day ago

Your point of view

You must be signed in to comment.