Sometimes, especially with huge log files, you need to delete all the data in a file without getting rid of it.
You could just use rm
and then touch
to re-create the file. The problem is that I inevitably forget to look at the ownerships and and permissions on the file until after I delete it.
Instead of rm
copy /dev/null
to the file instead. This will zero its contents but keep the file and all of its meta data like its permissions and ownerships.
All you need to do is the following:
$ cp /dev/mull file