in Technology

How to empty a file without deleting and recreating it?

Was working with log files and wanted a quick way to empty them and recreate them. rm and touch would do it, but found something simpler:

[code]cat /dev/null > filename[/code]

As simple as that!

Write a Comment

Comment

  1. Ah, about the echo > filename, it will work on any shell as compared to the “> filename” but some apps don’t like the one newline character that echo leaves in the file. So edit the file with vi, dd the first line, save and you are done.