Date scripting

Jacques B. jjrboucher at gmail.com
Fri Mar 24 03:14:24 UTC 2006


On 3/23/06, Chris Norman <cnorman at rnibncw.ac.uk> wrote:
> Hi people,
> I need to check files to see how old they are.
>
> How can I do this from within a backup script?
>
> I need to see if they are over a month old, and if so delete them. How do I
> get they're last modified stamp please?
>

If you use the following command
stat -c %y filename
it will return the last modified time stamp only for a file.
Compare that to the current date using the date command
You could parse out the date either using the awk command, or simply
using string manipulation (I forget the syntax off hand, but I have it
in my notebook at work).
Wouldn't be a particularly difficult thing to do.

If you aren't certain how to go about it simply give me a few more
details and I can have a look at my notes tomorrow and bang a piece of
bash script (I'm assuming you are looking to do this in bash) to
incorporate into your existing script.

Jacques B.




More information about the fedora-list mailing list