Today had to write a line in a ksh script that would create an empty file of empty the file if it already existed. My shell script knowledge had become a bit rusty hear. In my head I thought the command touch would help me here. But touch does no more than create a file if not exists, but if the file exists then leave the content untouched, just set the modification and the access time. So no use.
To just recreate an existing file use the >
$ ls -l timestamps.sem
-rw-r--r-- 1 johannes johannes 416 Oct 11 11:34 timestamps.sem
$ touch timestamps.sem
$ ls -l timestamps.sem
-rw-r--r-- 1 johannes johannes 416 Oct 11 11:43 timestamps.sem
$ > timestamps.sem
$ ls -l timestamps.sem
-rw-r--r-- 1 johannes johannes 0 Oct 11 11:44 timestamps.sem