help with a bash script

Kurt Wall kwall
Mon May 17 12:00:43 PDT 2004


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
-- 
"If a camel flies, no one laughs if it doesn't get very far."
		-- Paul White



More information about the Linux-users mailing list