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
  • 84,289
naveen
  • 8,057
  • 4
  • 15
  • 14
  • You can use ls to know the time stamp then after you finish the find comand use touch command to modify the time stamp back again – Fat Mind May 12 '15 at 12:36
  • Thank you @FatMind can you give the syntax how to write? – naveen May 12 '15 at 12:40
  • I use the mobile now ... you can check this question it will help http://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file – Fat Mind May 12 '15 at 12:47

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
  • 84,289