Jeff Woods wrote:
> Hi, "e.e." donna. ;)
hi :-)
> 1. Simplest(?) solution, but may fail if the command buffer overflows due
> to many matching files and/or long paths:
> $ rm $(find ./logs -name 'access_log.*' -ctime +30)
command buffer overflows??
> 2. For *each* matching file, print the path and then invoke rm to delete it:
> $ find ./logs -name 'access_log.*' -ctime +30 -print -exec rm {} \;
>
> 3. For *each* matching file, echo a prettier message and then delete it:
> $ find ./logs -name 'access_log.*' -ctime +30 -exec echo Deleting: {} \;
> -exec rm {} \;
>
> 4. Pipe filenames to xargs which will prevent buffer overflow by invoking
> rm (only) as many times as needed:
> $ find ./logs -name 'access_log.*' -ctime +30 |xargs rm
>
> 5. Same flaws as example 1, but otherwise does the same as example 3 in an
> easier to read manner:
> $ for Z in $(find ./logs -name 'access_log.*' -ctime +30)
> > do
> > echo Deleting: ${Z}
> > rm ${Z}
> > done
>
> I'd probably use example 4, but 3 and 5 both have merit too. All the
> examples invoke "find" only once, but only example 1 invokes "rm" just
> once.
(just playing devil's advocated...but...) why are you saying that rm is only
invoked once for example #1?
(yes, i know the answer....i think, however, there are wondering minds out
there...)
> All the other examples invoke "rm" (and where present "echo") once
> for each file. Example 4 invokes "xargs" once and "rm" as few times as
> feasible (probably just once) passing multiple filenames to each invocation.
>
> Note the "invoke" above means "fork and exec", which means "create a new
> process". Unless you know the number of files will be small and/or you
> don't care about performance issues, examples 2, 3 and 5 may be ill-advised.
in this particular case, there are very few files to purge.
> I haven't tested most of these so there may be typos or other flaws. I
> suggest you experiment with the above replacing "rm" with "echo would
> remove" or "echo ls -ldc" to see what happens.
you think, huh? :-)
> I'm not sure whether you prefer to use "-ctime" or "-mtime" or "-atime" or
> one (or more) of the other filters available in "find".
i looked at find's man text....and found the descriptions for ctime, mtime and
atime to be 'lacking' at best....different world....different rules, i guess.
so in this 'different world' -- is there a more common way of handling the
'build up' of log files?
> And if "find" on MPE/iX supports "-daystart" you may want to
> add that.
seems to me it does....
> Since this example is very similar to my favorite list of "most useful"
> Unix command-line tools that I find myself frequently using and
> recommending, I'll list them here and where you may find them documented:
thanks :-)
> To borrow a slogan from Nissan a few years back: Enjoy the ride! :)
only if i have to :-) - d
--
Any sufficiently advanced technology is indistinguishable from magic.
- Arthur Clarke
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|