Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update file, but not alter file modify date. Can it be done?

Tags:

linux

In Linux, can i change file content, but keep the same modification date of that file? If yes, then how? Thanks.

like image 533
AD. Avatar asked Nov 11 '11 14:11

AD.


People also ask

Can you change date modified file?

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.

How do I edit a file without changing the timestamp?

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.


3 Answers

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
like image 117
bilash.saha Avatar answered Sep 24 '22 17:09

bilash.saha


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.

like image 36
Kent Avatar answered Sep 21 '22 17:09

Kent


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.

like image 31
biggdman Avatar answered Sep 21 '22 17:09

biggdman