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.
Tell me more
×
Server Fault is a question and answer site for
professional system and network administrators. It's 100% free, no registration required.
|
|
|||
|
|
|
|
|||||||||||||
|
|
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 |
|||
|
|