Quick question about the command find.

Maxime Alarie malarie at processia.com
Fri Jun 4 14:18:44 UTC 2010


I know its dangerous, but im okay with it..   here is why

 

/dev/sda1:/var/backups  synchs  to  /dev/sdb1:/backup  every night.  AND
once a week : /dev/sdb1:/backup synchs to  this external  usb disk
/dev/sdc:/backup (offsite)

 

Sda1 and sdb1 are 250GB disks...  sdc is 1TB.  I want to erase 15 days+
old backups from  sda1 and sdb1 J

 

I will try your commands. Thanks much for the help guys.

 

 

 

From: ubuntu-users-bounces at lists.ubuntu.com
[mailto:ubuntu-users-bounces at lists.ubuntu.com] On Behalf Of Marc Farnum
Rendino
Sent: 04 June 2010 10:07
To: Ubuntu user technical support,not for general discussions
Subject: Re: Quick question about the command find.

 

any find that deletes (or uses -exec) is potentially dangerous; you've
been warned. :)

 

that said, try this:

 

find /path -mtime +15 -print0 | xargs -0-n 1 rm

 

using "-print0" avoids problems with "strange" characters in pathnames.

using "-n 1" causes it to execute with a single pathname at a time; less
efficient though safer.

 

btw: removing a directory based on its the mod date is maybe not what
you want - said directory may very well have files within it, that are
*newer* than 15 days.

 

so i've deliberately left an "error" in the above; it'll attempt to
apply the "rm" to dirs and give you errors; you can then use those
messages to review those dirs and decide if you do want to delete them.

 

if you *really* want to delete dirs too, in one step:

 

find /path -mtime +15 -print0 | xargs -0 rm -r

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20100604/4b39c837/attachment.html>


More information about the ubuntu-users mailing list