There's a nifty trick to empty the content of a file by redirecting nothing to it (not in the sense of not redirecting anything).
In this case a simple redirection (notice no command before ">") to the file and the contents are gone.
If you have noclobber variable set use:
This also works with aliases
Just set the alias to your shell's profile and you're set.
Pay great attention. NOCLOBBER variable can save you from accidental file overwrites from output redirection, but not from forced redirection (>|)
Related article: How to prevent accidental file overwrites from output redirection
Post comment:
0 comment(s) to How to empty/delete file content in Linux/BSD/Unix:
Home | Archives | Sitemap | About | Contact