Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 exptools 1/6/84; site iham1.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!iham1!fcy
From: fcy@iham1.UUCP (Fred Yankowski)
Newsgroups: net.unix
Subject: Re: creating pipes in find(1)
Message-ID: <225@iham1.UUCP>
Date: Wed, 3-Oct-84 11:09:39 EDT
Article-I.D.: iham1.225
Posted: Wed Oct  3 11:09:39 1984
Date-Received: Thu, 4-Oct-84 02:43:57 EDT
References: <12378@sri-arpa.UUCP>
Organization: AT&T Bell Labs, Naperville, IL
Lines: 45


In UNIX System V Release 1, 'find' processes its '-exec' arguments
with 'execvp(II)', not 'system(III)'.  This means that *no* shell
processing is done:  '|', '&', ';', '(', etc. are not interpreted by
the shell.  The command

	find / -type f -exec cat {} \| lpr \;

will then execute

	cat "file" "|" "lpr"

for each file "file" found by 'find' (got that?).
That is, 'cat' is executed with three arguments: "file", "|", and "lpr".

One handy idiom for processing files found by 'find' is:

	find dir  -print | xargs 

For example:

	find / -type f -print | xargs -n1 lpr

does what seems to be desired in the first (faulty) 'find' command
above.  Even better is

	find / -type f -print | xargs lpr

in which 'xargs' repeatedly gathers as many file names as fit in an
internal buffer and executes 'lpr' against each such list of file
arguments.  The improvement is in execution time, since 'lpr' is
fork/execed once for each list of files, rather than for each file
alone.

Similarly, cleaning out a directory is better accomplished with

	find . -type f -print | xargs rm

rather than

	find . -type f -exec rm {} \;


    Fred Yankowski ::: AT&T Bell Laboratories ::: ihnp4!iham1!fcy
			  IH 6B-216  x6902