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

Go to the Nth line of file [text editor]

Terminal - Go to the Nth line of file [text editor]
vi +4 /etc/mtab
2011-09-15 19:18:00
User: totti
Functions: vi
1
Go to the Nth line of file [text editor]

This is not printing, real editing using the text editor.

Alternatives

There are 3 alternatives - vote for the best!

Terminal - Alternatives
sed -n 13p /etc/services
sed -n '15p' $file
2011-09-16 07:27:11
User: marek158
Functions: sed
Tags: goto
0

Prints exactly 15th line of $file. You can also specify a range:

sed -n '2,18p' $file - this will print lines 2 to 18, inclusive.

echo "13" | ed /etc/services
2011-09-15 19:37:49
User: muonIT
Functions: echo ed
Tags: goto
-5

Nth line of a file - dirty hack way. I haven't used ed in ages ;-)

head -n 13 /etc/services | tail -n 1
2011-09-15 19:39:49
User: muonIT
Functions: head tail
Tags: goto
-5

Silly approach, but easy to remember...

Know a better way?

If you can do better, submit your command here.

What others think

What's up with the down-vote sans comment?

+1 from me

sometimes I'll get a "syntax error on line 54", so I'll launch vi and then key in 53 and then the down arrow. This saves me one small step, (though not any keystrokes)

Comment by unixmonkey365 193 weeks and 2 days ago

Your point of view

You must be signed in to comment.