LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-04-2008, 05:32 PM   #1
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Rep: Reputation: 0
Question Script to change all the file's dates with condition ... ?


Hi,

I really need your help
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 ?

THANKS !
RB

Last edited by raf_iso; 03-04-2008 at 05:34 PM.
 
Old 03-04-2008, 06:14 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
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.
 
Old 03-04-2008, 06:25 PM   #3
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
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.
 
Old 03-05-2008, 09:30 AM   #4
raf_iso
LQ Newbie
 
Registered: Jul 2005
Posts: 18

Original Poster
Rep: Reputation: 0
BIG Thanks osor !

It's works perfectly ! Amazing
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script to change file name and append the date john_551 Linux - Software 4 08-26-2006 06:56 AM
Script to change date in filename minus one day ft77 Linux - General 3 06-02-2006 09:56 AM
Shell script: substitute a file's content according to a map? Chowroc Programming 11 11-15-2005 04:08 AM
If condition in script imsajjadali Red Hat 5 06-07-2004 06:52 AM
How can an ordinary user change a file's ownership? garymansell Red Hat 1 04-01-2004 10:35 AM


All times are GMT -5. The time now is 01:40 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration