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.

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:



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.

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 107 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 107 weeks and 3 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 102 weeks and 4 days ago

dG in vim is better, I think...

Comment by Zulu 102 weeks and 3 days ago

Your point of view

You must be signed in to comment.