Reputation: 237
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
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
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
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
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