Thursday, April 12, 2012

how to empty / reset an existed file?

Say, I have to create a new file regardless of the existence of the file.

"touch file" does not work in that case, because it will only update the time tag if a file is already existed.

One way I can think of is:

(rm file && touch file) || touch file

Other ways I got from this page (

cat /dev/null > file.txt

or the simplest way:


No comments:

Post a Comment