In Linux, can i change file content, but keep the same modification date of that file? If yes, then how? Thanks.
Unfortunately, this isn't possible. You can view certain and change certain file attributes in File Explorer, but you can't change the last viewed, edited, or modified dates.
We can use one of the touch command's option -r (reference) to preserve file timestamps after editing or modifying it. The -r option is used to set the timestamps of one file to the timestamp values of another. As stated already, if we change the contents or metadata of this file, the timestamps will also change.
Get what is the modification Date of your file.
Change your files content and then you can change the modification date by touch
command.For example
touch -m -t 09082000 file
to change the modification time to 8 sep, 20:00.
You can change the modification date to the past too, for 10/15/1998 12:30 the command would be something like this:
touch -m -t 19981015123000 file
another possibility might be a symbolic link?
if you have alink->a.txt
, you change the content of a.txt, the last modi time of alink won't be updated.
You can memorize the modification date before modifying the content; After the content modification, you can modify back the date to the initial value. It can be done in Linux from the command line. For example:
touch -t 09082000 file to change the modification time to 8 sep, 20:00. More info can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With