Reputation: 2140
I am using this current find command:
find . -name "313958000002101817.pdf"
I am currently in a directory that looks similar to this:
/n01/data/adf/fp08_traffic/jobs/FB
Within this directory, I have IDs so that my directory structure looks similar to this:
/n01/data/adf/fp08_traffic/jobs/FB/1234
/n01/data/adf/fp08_traffic/jobs/FB/1235
/n01/data/adf/fp08_traffic/jobs/FB/1236
I know that the PDFs that I am looking for are in this job directory:
/n01/data/adf/fp08_traffic/jobs/FB/"ID"/PDFs
Is there a way to throw a wildcard for a job directory in the middle of the string?
Upvotes: 0
Views: 50
Reputation: 295766
If the number of per-job directories isn't so large that it won't fit on a command line, this is trivial:
find /n01/data/adf/fp08_traffic/jobs/FB/*/PDFs -name "313958000002101817.pdf" -print
What we're doing here is instructing the shell to pass a list of job directories to find
. That won't work beyond a point, though. Assuming that you're dealing with a larger set...
find /n01/data/adf/fp08_traffic/jobs/FB -mindepth 2 -maxdepth 2 -type d -name PDFs \
-exec sh -c 'exec find "$@" -name "313958000002101817.pdf" -print' _ {} +
The first find
generates a list of PDFs
directories. -exec sh -c '...' _ {} +
then passes those directory names on the argument list of a shell (as many to each shell invocation as possible for efficiency), which then passes them in the appropriate location of a new find
command per batch. (The shell is needed because -exec ... {} +
only allows substitutions at the end of an argument list, not at any prior location, whereas find
needs the list of directories to come before the list of predicates).
Upvotes: 4