Amend File Without Changing Timestamp

Hi,

Is it possible to amend a file without changing the last modified date?

If it is, how do you do it?

If it's not, is there a way to create an empty file with the same timestamp as another file?

I know you can use touch -t yyyymmddhhmm.ss filename but, I would want the file to have the exact same timestamp as another file.

Any help would be greatly appreciated.

Thanks

****EDIT****
Sorry, I forgot to mention. I'm trying to script using bash.

You will use touch option -r (reference file) with will create a file with exact same timestamp as file you referenced to.

Check man touch

1 Like

Thanks very much, Peasant.

I looked through the man page for touch and must've missed it.

Thanks!

Actually:

touch -r file1 file2...

will set the access time and the modification time of file2 and any other file operands to match the access time and the modification time of file1. If you just want to reset the modification time, use:

touch -m -r file1 file2...
1 Like

Thanks Don.

I realised what Peasant meant with his post and it worked perfectly.

Thanks for the info on touch -m though.