AD.
AD.

Reputation: 237

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

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

Upvotes: 5

Views: 11873

Answers (4)

TabeaKischka
TabeaKischka

Reputation: 883

As I had a similar problem now and found this question via google, I'll give an easy, automatic solution. I store the current modification time in the variable CURRENT, then after modifying the file, I set the modification time back to its original time via touch. Please note that getting the timestamp for current is a bit clumsy, you might need to modify it a bit.

FILE=test.txt
touch $FILE
CURRENT=$(date -r $FILE +%Y%m%d%H%M)
# run your command here
touch $FILE 
touch -a -m -t $CURRENT $FILE

Upvotes: 2

bilash.saha
bilash.saha

Reputation: 7306

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

Upvotes: 10

biggdman
biggdman

Reputation: 2106

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.

Upvotes: 2

Kent
Kent

Reputation: 195079

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.

Upvotes: 2

Related Questions