Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/*' \
share|improve this question

migrated from Oct 12 '12 at 12:17

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

Is that what you mean?

find . \( \! -iregex ^./bin/.\* -o -iregex ^./include/something/.\* \) \
    -name \*.php
share|improve this answer
No - but I've rewrote the question so hopefully I'm explaining myself better now. – yoavf Dec 9 '09 at 9:20
yoavf, so I've edited my reply – Michael Krelin - hacker Dec 9 '09 at 9:47

GNU find

find . -name "*.txt" ! -iregex ".*/bin/.*"
share|improve this answer

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

share|improve this answer
find /bin /bin/php -maxdepth 1 -name "*.php"

Proof of concept

$ tree /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


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

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .