How to truncate a file without updating its timestamp?
Posted: 15 Mar 2024 08:59
I have a Makefile, that needs to run under cmd. It contains the following command:
@-touch -r "/tmp/ccprwrlE.ltrans0.o" "/tmp/ccprwrlE.ltrans0.o.tem" > /dev/null 2>&1 && mv "/tmp/ccprwrlE.ltrans0.o.tem" "/tmp/ccprwrlE.ltrans0.o"
To summarize, it copies the timestamp of the ".o" file onto a ".o.tem" file. Afterwards, it renames the ".o.tem" file to be ".o", overwriting it in the process.
The .o.tem file is zero bytes, because it didn't exist prior, and touch created it.
The purpose is to truncate a file, while not modifying its modified date.
My question is, how can I do this using cmd.exe?
I did some searching on my own already. I found this mentioned as a "touch equivalent":
copy /b filename.ext +,,
However, this is going to destroy the timestamp, so it doesn't do the same thing
Is there any equivalent oneliner I can use?
@-touch -r "/tmp/ccprwrlE.ltrans0.o" "/tmp/ccprwrlE.ltrans0.o.tem" > /dev/null 2>&1 && mv "/tmp/ccprwrlE.ltrans0.o.tem" "/tmp/ccprwrlE.ltrans0.o"
To summarize, it copies the timestamp of the ".o" file onto a ".o.tem" file. Afterwards, it renames the ".o.tem" file to be ".o", overwriting it in the process.
The .o.tem file is zero bytes, because it didn't exist prior, and touch created it.
The purpose is to truncate a file, while not modifying its modified date.
My question is, how can I do this using cmd.exe?
I did some searching on my own already. I found this mentioned as a "touch equivalent":
copy /b filename.ext +,,
However, this is going to destroy the timestamp, so it doesn't do the same thing
Is there any equivalent oneliner I can use?