Here's a simple one. How do I truncate an existing file in linux? That is, how do I empty the contents of the file but keep the file. I can always delete the file then touch
it but I was wondering if there's a single command that'll get the job done.
>output-file
-- shortest possible version.This solution is more efficient than cat, because it doesn't create a subprocess (in addition to the shell process):
You may do easy :)
I'm sure a harder-core *nix person will have a better idea, but I've always done:
To truncate files.
echo -n > YOURFILE
will remove file contents and keep the file, structure and permission intact.