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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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



Delete lines in a text file fast

Terminal - Delete lines in a text file fast
2013-04-10 10:34:39
User: techie
Delete lines in a text file fast

If you want to delete lines fast then all you need to do is vi/vim a text file, type in the amount of lines you want to delete (in my example I wanted to delete 10056 lines) followed by dd (no spaces). There will be no output so becareful with what number you type.


There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

This is very-very basic vi/vim knowledge - without you will propably fail to use the editor. Therefore IMHO highly redundant to mention it here. Sorry ..

Comment by Paule 262 weeks and 4 days ago

I'm inclined to agree with Paule, also I'm having difficultly framing a situation in which I want to delete 10056 lines without some idea of what that range might be, why 10056 lines, other than the fact that it a big(ish) number and therefore provides some context for "fast"? Anyhow, for such a task there is no need to open the file:

sed -i '1,10056d' file.txt

The question of range aside, should I remove such a number of lines I'd probably want to keep the original and make a revision:

sed '100,700d' revision1.txt > revision2.txt

Comment by khayyam 262 weeks and 4 days ago

I had a very large file with many different configurations in but #'d out.. I used vim and got to the line that I needed the file to start at which was 1057 so I went back to the top of the file and used 1057dd.. When I posted I used an extra 0 in the middle. It would have been a mess if I did that in the command line lol

Comment by techie 257 weeks and 4 days ago

dG in vim is better, I think...

Comment by Zulu 257 weeks and 4 days ago

Your point of view

You must be signed in to comment.