xargs / FS-maintenance question

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Fri Oct 1 21:27:39 UTC 2004


On Fri, Oct 01, 2004 at 04:14:28PM -0400, Fraser Campbell wrote:
> On Friday 01 October 2004 15:30, Lennart Sorensen wrote:
> 
> > Just be aware the example fails badly on filenames with spaces. ?For
> > that you should use find's -print0 option along with xarg's -0 option.
> > Null seperated filenames rahter than whitespace seperated.
> 
> I'm sure y'all know this but just a quick tip to save the fast fingered ...
> 
> print0 is a very useful option, it is also a dangerous option for someone who 
> might skim the man page without grokking it 100% ... like me ;-)
> 
> "find . -type f -mtime +7" will print all files that have not been modified in 
> at least 7 days.
> 
> "find . -type f -print0 -mtime +7" will print all files.  -print0 must be the 
> last arument, very important when doing something like:
> 
>    find . -type f -mtime +7 -print0 | xargs -r -0 rm -f
> 
> Fortunately there were backups in my case :-(

find uses lazy evaluation (that's a good feature) so each option is
checked in order, and if a fail is encountered, not followed by an or
(-o I believe) it will go on to the next file, otherwise it keeps
checking options.  -print and -print0 are simply true and while
returning true print the name.  by default find sticks a -print at the
end unless -exec or something else is there since it figures some side
effect should be performed.

I always test my find commands using: find ..... | xargs echo command
options

echo is a good thing, lets you see if the result looks sane before
really doing it.

Lennart Sorensen
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list