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 (http://www.tech-recipes.com/rx/2993/how_to_empty_or_clear_the_contents_of_an_existing_unix_file/):
cat /dev/null > file.txt
or the simplest way:
>file.txt
No comments:
Post a Comment