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: Andreas R.
Subject: Re: Question about find(1): How to invoke multiple commands in exec?
Date: Fri, 23 Jul 2004 15:15:57 +0200
User-agent: KNode/0.7.1

mike burrell wrote:

> 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.

Yes, thanks.
The final result is used to find the directories with most files in them (we 
have quota limitation on number of files on our university computers):
find . -mindepth 1 -maxdepth 1 -type d -exec sh -c 'find {} -print | wc -l  
| perl -ane "\$a = \$F[0]; print  \"\$a\t\" " ' \; -printf "%f\n" | sort -n 
-r

The perl expression just substitues \n by \t in a weird way (I don't know 
how to do this in sed).



reply via email to

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