2

I have replaced word 'merchant' to 'capital' in files founded in the current directory using following command:

find * -type f -exec sed -i -e 's/merchant/capital/g' {} \;

but above command will modify the file date also, is there any way to stop file modification date?

Thanks in advance.

Maythux
  • 87,123
naveen
  • 8,307

1 Answers1

2

I don't think there is a clear solution for you.

But as a workaround solution.

Get the modification date of a file

stat file.txt | grep Modify

Now After completing what you did restore the previous modification date

touch  -m -t [[CC]YY]MMDDhhmm[.SS]

he following explains the above format:

  • CC – Specifies the first two digits of the year
  • YY – Specifies the last two digits of the year. If the value of the YY is between 70 and 99, the value of the CC digits is assumed to be
  • If the value of the YY is between 00 and 37, the value of the CC digits is assumed to be 20. It is not possible to set the date beyond January 18, 2038.
  • MM – Specifies the month
  • DD – Specifies the date
  • hh – Specifies the hour
  • mm – Specifies the minute
  • SS – Specifies the seconds

For example: changind modification date of a file of mine called url.txt

stat url.txt | grep Modify

output

Modify: 2015-05-04 09:42:28.148281881 +0300

change modification to 04/05/2016 20:05:04

touch -m -t 201605042005.04 url.txt 

Get sure that works

stat url.txt | grep Modify

output

Modify: 2016-05-04 20:05:04.000000000 +0300
Maythux
  • 87,123