How to clear text in a file?
Just open your terminal with CTRL+ALT+Tand type as
> hello.txt
that's it, your data in that file will be cleared with out opening it even .
Example:
The easiest way is to truncate a file is to redirect the output of the shell no-op command (:
) to the file you want to erase.
: > hello.txt
I have to do this all the time with log files. The easiest way I have found is with the following command:
cat /dev/null > hello.txt
This deletes allo of the content of the file, and leaves you with an empty file without having to open it in an editor, select text, any of that stuff. More specifically what it does is to replace the contents of the file with the contents of "/dev/null", or nothing. It's pretty slick, actually.
The only caveat is that the user you are currently logged in as must have write permission to said file.