help with a bash script

Joel Hammer joel
Mon May 17 12:00:43 PDT 2004


I have no idea of your file structure, but, find is your
friend.  The command below finds all regular files in the
same directory that are more than 5 days (1 day = 24 hours)
old or older.

ls -al $(find -atime +5 -maxdepth 1 -type f)
This works.

You could use:
rm  $(find -atime +5 -maxdepth 1 -type f)
Although I haven't tried this command out, not wanting to
erase anything important while I experimented....

If you have a lot of mail, it is possible that the command
line above might get too long. Then, the following might
work:

dir -1 | find -atime +5 -maxdepth 1 -type f > junk
while read a
do
rm $a
done < junk

man find 
is worth the read. But, it requires a some experimentation
to get the options figured out.

Joel


On Thu, Mar 18, 2004 at 05:10:21PM -0800, Marianne Taylor wrote:
> I have written a bash script to backup my IMAP mail each night.  Unfortunately 
> I haven't figured out a way to delete the older files.  I want to keep only 
> five days of backup, any ideas how I would pick out the older files and 
> delete them?
> 
> TIA
> _______________________________________________
> Linux-users mailing list
> Linux-users at smtp.linux-sxs.org
> Unsubscribe/Suspend/Etc -> http://smtp.linux-sxs.org/mailman/listinfo/linux-users



More information about the Linux-users mailing list