find question

H.S. hs.samix at gmail.com
Sat Jul 14 17:25:04 UTC 2007


Brian Fahrlander wrote:
> H.S. wrote:
>> Pete Holsberg wrote:
> [snipped]
> 
>>> Interesting! I used
>>>
>>> find / -name proc -prune -o -name .profile 2>/dev/null
>>>
>>> It did not run down the entire /proc hierarchy but it did report all 
>>> files with "proc" in their names, such as all the stuff under 
>>> /usr/src/linux-headers* !!
>>>
>>>
>> Try:
>> $> find / -path './proc' -prune -o -name .profile 2>/dev/null
> 
>> This if from the command I tried to search for *gz files in the current
>> directory's tree but excluding directory named dat:
>> $> find ./ -path  './dat'  -prune -o  -name "*gz"  -print
> 
>     OK, I'm intrigued; I'm also working on something.
> 
>     I'm searching a 1-wire filesystem looking for devices that have
> names like "[0-9A-F][0-9A-F]\.[0-9A-F]*".
> 
>     The problem is, I need to skip paths with "uncached" "alarm" and
> "bus.0" in their names.  And the examples I'm seeing aren't getting me
> there.  Either they leave behind the directory name (until -path) or
> other things start showing up.
> 
>    Like this:
> find /var/1wire -path './bus.0' -prune -o -name
> "[0-9A-F][0-0A-F]\.[[0-9A-F]*" 2>/dev/null
> 
>     Returns:
> /var/1wire/bus.0/1F.38C704000000
<SNIP>
>    Notice the "bus.0" still shows up.  What am I doing wrong?


Put the full path of the directory to be ignore before "-prune". So you
would try:
$> find /var/1wire -path '/var/1wire/bus.0' -prune -o -name
"[0-9A-F][0-0A-F]\.[[0-9A-F]*" 2>/dev/null

Or, you may want to use '*bus*' instead to exclude every path with bus
in it. Or maybe '/var/1wire/bus*' to exclude directories starting with
bus in /var/1wire.

To exclude multiple directories you need to use the OR construct using
"-o" like so (to exclude /var/1wire/bus* and /var/1wire/foo* ):
$> find /var/1wire \( -path '/var/1wire/bus.0' -o -path
'/var/1wire/foo*' \) -prune -o -name "[0-9A-F][0-0A-F]\.[[0-9A-F]*"
2>/dev/null

->HS





More information about the ubuntu-users mailing list