Thursday, 1 August 2019

Delete all lines in VI / VIM editor - Unix / Linux

Q) How to delete all the lines in a file when opened in a VI editor or VIM editor?



Those who are new to unix will use the dd to delete each and every line to empty the file. There is an easy way to delete all the lines in a file when opened in an Editor.

Follow the below steps to empty a file:
Go to command mode in the editor by pressing ESC key on the keyboard.
Press gg. It will take to the first line of the file.
Then press dG. This will delete from the first line to the last line.

See how simple it is to remove all the lines in a file. We will see how to empty the file when not opened in an editor. In unix /dev/null is any empty stream, you can use that to empty a file. The following commands shows how to empty a file

cat /dev/null > file

0 comments:

Post a Comment