Re: Best (most efficient method) recursive dir DEL
James Polley <[email protected]> Thu, 22 May 2014 17:22:44 +1000
| Newsgroups | gmane.org.user-groups.slug.general |
|---|---|
| Message-ID | <[email protected]> |
> On 22 May 2014, at 9:10, Kyle <[email protected]> wrote: > > Hi folks, > > I was wondering what is the best (as in most efficient method) for doing an automated, scheduled recursive search and DEL exercise. The scheduled part is just a cron job, no problem. But what's the most efficient method to loop a given structure and remove all (non-empty) directories below the top dir? > > The 3 examples I've come up with are; > > find <top_dir> -name <name_to_find_and_DEL> -exec rm -rf {} \; - what's the '\' for and is it necessary? > > rm -rf `find <top_dir> -type d -name <name_to_find_and_DEL>` - does it actually require the ' ` ' or are ' ' ' good enough? > > find <top_dir> -name '<name_to_find_and_DEL>' -type d -delete - or won't this work for a non-empty dir? How do you define "most efficient"? Run time? CPU cycles? Memory usage? Forks? Disk reads/writes? Readability/maintainability? My personal guess is that a find command that locates the things you want to delete and ends with "-print0 | xargs -0 rm -rf" will satisfy most of those criteria. (Xargs will stuff as many file names as it thinks will fit on the command line, but sometimes it gets ambitious - you might have to use "xargs -0 -n 100 rm -rf" to limit it to 100 file names per invocation of rm) > > Or is there a more efficient manner which I can slot into a cron job? > > Much appreciate the input. > > -- > ------------------------------------------------------------------------ > Kind Regards > > Kyle > > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html