LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Script to change all the file's dates with condition ... ? (http://www.linuxquestions.org/questions/programming-9/script-to-change-all-the-files-dates-with-condition-625719/)

raf_iso 03-04-2008 05:32 PM

Script to change all the file's dates with condition ... ?
 
Hi,

I really need your help :D
Our fileserver (linux) had a wrong system date (+1 year) so now all the file file's dates are in the future.

I'm trying to do a script but my unix knowledge is very limited :)

Could you help please ?

- loop in all the /data filesystem
-- check if the current file's date is above june 2008
---- if yes, change is to 01.01.2008

Do you have any idea :D ?

THANKS !
RB

osor 03-04-2008 06:14 PM

You can use the touch command along with the find command to accomplish what you want (I believe).

Something like the following:
Code:

#!/bin/bash

touch -t '200806010000' basefile
find . -newer basefile -exec touch -t '200801010000' '{}' ';'
rm basefile

You can change . to the directory in which you want to make the replacements.

Notice that this works only with modification times. In particular, changing access times to something different from the present is not reliable. If you absolutely must have this functionality, you must remount the partition with the noatime option.

raf_iso 03-04-2008 06:25 PM

Quote:

Originally Posted by osor (Post 3078254)
You can use the touch command along with the find command to accomplish what you want (I believe).

Something like the following:
Code:

#!/bin/bash

touch -t '200806010000' basefile
find . -newer basefile -exec touch -t '200801010000' '{}' ';'
rm basefile

You can change . to the directory in which you want to make the replacements.

Notice that this works only with modification times. In particular, changing access times to something different from the present is not reliable. If you absolutely must have this functionality, you must remount the partition with the noatime option.


Wow :) THANKS YOU. I'll try it.

raf_iso 03-05-2008 09:30 AM

BIG Thanks osor !

It's works perfectly ! :) Amazing ;)


All times are GMT -5. The time now is 08:50 AM.