help with a bash script

Brad De Vries devriesbj
Mon May 17 12:00:45 PDT 2004


--- Kurt Wall <kwall at kurtwerks.com> wrote:
> In a 0.4K blaze of typing glory, 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?
> 
> At first blush, I would use the find utility to
> locate all of the files
> in that directory  that are older than five days,
> then pipe the output
> to xargs, thus (untested):
> 
> --- cut---
> #!/bin/sh
> cd /some/dir
> find . -type f -mtime +5 | xargs rm
> --- cut ---
> 
> This finds all regular files (-type f), starting in
> the current 
> directory (.), that were modifed more than 5 days
> ago (-mtime +5), 
> pipes the output to xargs (| xargs), and then passes
> the filenames to rm.
> 
> HTH,
> 
> Kurt

Is there any reason for not using the -exec parameter
of the find command:

find . -type f -mtime +5 -exec rm {} \;

Brad.


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com



More information about the Linux-users mailing list