|
Prev: getopt arguments
Next: Derive a sum of a column
From: Scott McMillan on 3 Jul 2006 12:26 On 03 Jul 2006 16:07:57 GMT, my <address(a)is.invalid> wrote: > > Hi, > >Occasionally I post files on my ftp site for others to download. >I have the following line in my crontab to delete them when they >become 7 days old. It has worked great until, if I make a >subdirectory under outgoing, although it deletes the files in the >subdir, it does not delete the sub directory. Why not? > > 3 23 * * * find /ftp/pub/users/fubar/outgoing -follow -name "*" -type f -mtime +7 -print | xargs rm -rf > > Thanks, > > Vic > > The "-type f" portion will only find *files*, and the rm -rf is only acted upon what the find command locates. If you want to remove everything under /ftp/pub/users/fubar/outgoing then drop the "-type f". Scott McMillan
From: Jeremiah DeWitt Weiner on 3 Jul 2006 12:23 my <address(a)is.invalid> wrote: > although it deletes the files in the > subdir, it does not delete the sub directory. Why not? > 3 23 * * * find /ftp/pub/users/fubar/outgoing -follow -name "*" -type f -mtime +7 -print | xargs rm -rf Because you said "-type f". That means "files". It's never going to delete directories if all you give it is the names of files. -- Oh to have a lodge in some vast wilderness. Where rumors of oppression and deceit, of unsuccessful and successful wars may never reach me anymore. -- William Cowper
From: Jon LaBadie on 3 Jul 2006 13:05 Scott McMillan wrote: > On 03 Jul 2006 16:07:57 GMT, my <address(a)is.invalid> wrote: > >> Hi, >> >> Occasionally I post files on my ftp site for others to download. >> I have the following line in my crontab to delete them when they >> become 7 days old. It has worked great until, if I make a >> subdirectory under outgoing, although it deletes the files in the >> subdir, it does not delete the sub directory. Why not? >> >> 3 23 * * * find /ftp/pub/users/fubar/outgoing -follow -name "*" -type f -mtime +7 -print | xargs rm -rf >> >> Thanks, >> >> Vic >> >> > > The "-type f" portion will only find *files*, and the rm -rf is only > acted upon what the find command locates. If you want to remove > everything under /ftp/pub/users/fubar/outgoing then drop the "-type > f". > Possible danger here is that the top-level, "outgoing" directory would meet the -name '*' -mtime +7 criteria. In that case it would be "rm -rf'ed" Perhaps the starting path for find should be /ftp/pub/users/fubar/outgoing/* (assuming no "dot" or "oddly named" files/directories)
From: Scott McMillan on 3 Jul 2006 13:55 On Mon, 03 Jul 2006 13:05:21 -0400, Jon LaBadie <jxlabadie(a)axcxmx.org> wrote: >Scott McMillan wrote: >> On 03 Jul 2006 16:07:57 GMT, my <address(a)is.invalid> wrote: >> >>> Hi, >>> >>> Occasionally I post files on my ftp site for others to download. >>> I have the following line in my crontab to delete them when they >>> become 7 days old. It has worked great until, if I make a >>> subdirectory under outgoing, although it deletes the files in the >>> subdir, it does not delete the sub directory. Why not? >>> >>> 3 23 * * * find /ftp/pub/users/fubar/outgoing -follow -name "*" -type f -mtime +7 -print | xargs rm -rf >>> >>> Thanks, >>> >>> Vic >>> >>> >> >> The "-type f" portion will only find *files*, and the rm -rf is only >> acted upon what the find command locates. If you want to remove >> everything under /ftp/pub/users/fubar/outgoing then drop the "-type >> f". >> > >Possible danger here is that the top-level, "outgoing" directory would >meet the -name '*' -mtime +7 criteria. > > In that case it would be "rm -rf'ed" > >Perhaps the starting path for find should be /ftp/pub/users/fubar/outgoing/* >(assuming no "dot" or "oddly named" files/directories) Ah yes, good call. Assuming the "outgoing" directory met the rest of the find criteria, it would indeed be removed. Thanks for pointing that out, Jon. Scott McMillan
From: Randal L. Schwartz on 3 Jul 2006 15:26
>>>>> "Jon" == Jon LaBadie <jxlabadie(a)axcxmx.org> writes: Jon> Possible danger here is that the top-level, "outgoing" directory would Jon> meet the -name '*' -mtime +7 criteria. Jon> In that case it would be "rm -rf'ed" Jon> Perhaps the starting path for find should be /ftp/pub/users/fubar/outgoing/* Jon> (assuming no "dot" or "oddly named" files/directories) A much bigger danger is someone making a directory named "foo\n", and within that a directory named "etc", and then touching a file named passwd there. Wait 7 days, and your /etc/passwd file goes away. Oops. NEVER use xargs without -0 NEVER use find without -0 Understand? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn(a)stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- Posted via a free Usenet account from http://www.teranews.com |