Date scripting

Jim hd at jcshome.net
Fri Mar 24 02:45:36 UTC 2006


Chris Norman 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?
>
> Cheers,
>
> Chris Norman
> <!-- chris.norman4 at ntlworld.com -->

Use the find command. It is a very powerful command to use. Check the 
man pages as it can be used for many things.

 When you use the find command to delete old files ALWAYS specify the 
directory name to search down through. If you use a period "." it uses 
your current directory and if you happen to be in the root, say goodbye 
to your box.  Very dangerous. Also be aware that it will also delete any 
hidden or system files that it has permissions to.

What I always do is use the find command with echo first. That way I 
will see exactly which files it will delete.

find /home/jim -name "*" -mtime +30 -exec echo {} \;   <- This just 
displays the filenames

find /backup -name "*" -mtime +30 -exec ls -l {} \;   <- This will show 
you the listing so you can verify the dates

Double and triple check before putting your script into production.

Jim




More information about the fedora-list mailing list