help with a bash script

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


xargs has always been an extra nuisance to me...

But,
shouldn't these scripts have some provision for file names with
blanks and other annoying characters?

So, shouldn't your script be:

     find . -type f -mtime +5 | xargs -i{} rm {}

My script has the same problem.

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

On the other hand, I do not think my original script can be salvaged so
easily:
     rm  "$(find -atime +5 -maxdepth 1 -type f)"
Doesn't work. It is all one long line.

Joel 

On Thu, Mar 18, 2004 at 09:01:55PM -0500, Kurt Wall 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
> -- 
> "If a camel flies, no one laughs if it doesn't get very far."
> 		-- Paul White
> _______________________________________________
> 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