views:

157

answers:

4

I am using find in a Bash script. How can I modify that code to include a specific directory under 'bin' , ie './bin/php/' (while still ignoring all other sub-directories of 'bin')?

Current code:

find . -name '*.php' \
-and ! -path './bin/*' \
+1  A: 

Is that what you mean?

find . \( \! -iregex ^./bin/.\* -o -iregex ^./include/something/.\* \) \
    -name \*.php
Michael Krelin - hacker
No - but I've rewrote the question so hopefully I'm explaining myself better now.
yoavf
yoavf, so I've edited my reply
Michael Krelin - hacker
+1  A: 

GNU find

find . -name "*.txt" ! -iregex ".*/bin/.*"
+1  A: 
find /bin /bin/php -maxdepth 1 -name "*.php"

Proof of concept

$ tree /bin
/bin
|-- ash
|-- dont_search
|   |-- hide_me.php
|   `-- hide_me.txt
|-- du
|-- file.php
|-- fmt
|-- php
|   |-- hide_me.txt
|   `-- show_me.php
`-- zsh

2 directories, 184 files

Result

$ find /bin /bin/php -maxdepth 1 -name "*.php"
/bin/file.php
/bin/php/show_me.php

Notice that /bin/dont_search/hide_me.php did not match

SiegeX
+1  A: 

Try this:

find . ./bin/php -path ./bin -prune -o -print

This will ignore files that are within ./bin, too, though.

By the way, it's "find" rather than "Bash find".

Dennis Williamson