help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about find(1): How to invoke multiple commands in exec?


From: mike burrell
Subject: Re: Question about find(1): How to invoke multiple commands in exec?
Date: Mon, 19 Jul 2004 14:48:38 GMT
User-agent: tin/1.6.0-20030714 ("Vatersay") (UNIX) (Linux/2.6.2 (i686))

Andreas R. <not_a_real_address@nowhere.com> wrote:
> If for example I want to count all the files in a subdirectories of the 
> current directory, I thoght I would need something like that:
> 
> find . -type d -exec find "{}" -print | wc -l \;

The | is a special character for the shell.  When parsing a command-line, it
will read commands separated by the | character.  "find . -type d -exec find
"{}" -print" will be read as one command, which will be piped to "wc -l \;". 

The immediate thought is to just escape the pipe.  Unfortunately, find will
not parse the pipe itself, so the only way I've thought of to solve this
problem is to get find to invoke a shell:

find . -type d -exec sh -c "find {} -print | wc -l" \;

I hope this is what you want.

-- 
 /"\                                                 m i k e   b u r r e l l
 \ /     ASCII RIBBON CAMPAIGN                                mikpos@shaw.ca
  X        AGAINST HTML MAIL,
 / \      AND NEWS TOO, dammit


reply via email to

[Prev in Thread] Current Thread [Next in Thread]