View Single Post
  #5  
Old 11-13-2007, 04:23 PM
downrange downrange is offline
Senior Member
 
Join Date: Feb 2007
Posts: 157
Default Re: shell script question

IMM whatever cycle you're doing this over you don't really need to do any calculating. What I mean is, if you do this every day but only want 3 days-worth of backups then sort by date and delete everything but the newest 3 copies:

/bin/rm -f dummy `/bin/ls -t <filename spec> | sed -e 1,3d`

Those are backticks, "N" in "Nd" controls how many copies and obviously test this out where you can do no irreparable damage.

And pick your <filename spec> well enough to ensure that the only thing "ls" parses is the group of files you intend it to examine.
Reply With Quote