How to delete a line from a file

Created: 2014-12-15 — modified: 2014-12-15 — tags: bash vim

If you know what line to delete...

Say, for example, you got this message from SSH:

Offending key in /home/alexey/.ssh/known_hosts: 6

and you know what it means and you know why it's there and you want to remove it.


First, you can open your favourite text editor:

$ vim .ssh/known_hosts

and then, type this to Go to the 6th line, Delete it, and quit with saving (ZZ):



But there's an easier way!

just use sed:

$ sed -i 6d .ssh/known_hosts

to edit file In-place by Deleting 6th line.

Much less typing, don't you think?