But if I change find command to find ${path} -path "*/a" -name "script.*.sh" the script does output nothing.
Indeed, it must not. A file matching the predicate -path "*/a" cannot also match the predicate -name "script.*.sh".
My logic find all files with pattern /tmp/test/*/a/script.*.sh what
I say with find ${path} -path "*/a" -name "script.*.sh".
You seem to be assuming that the value of $path is /tmp/test. In that case, it's unclear to me why you are making this so complicated. Since you can exactly describe the paths you want via a glob, I would be inclined to leave find entirely out of the picture:
files=("${path}"/*/a/script.*.sh)
But if you want to do it with find, then I don't see the point of combining -name and -path for this case. As you already observed, your original find command does the job. And it's simpler and clearer.
Alternatively, you could move the partial-path matching to the starting-point list:
find ${path}/*/a -maxdepth 1 -name "*script.*.sh"
- What does
find ${path} -path "*/a" -name "script.*.sh" command do in real?
It searches for files in the subtree rooted at ${path} whose paths (starting with ${path}) match the pattern */a, and whose basenames match the pattern script.*.sh. Each in full. The paths of any files matching both criteria will be printed, but the conditions cannot both be satisfied for the same file, so nothing will be printed.
- There is debug mode in the
find? I mean how does it understand what I say to it (example: path(s) where it will search, without find . -name "*te.st*", just ./*/*te.st*).
POSIX does not specify any debug facilities for find, but inasmuch as you have tagged linux and ubuntu, you are almost certainly using the GNU findutils version of find. This implementation does have debug facilities, which are documented on its manual page. You are looking for the -D option. It's unclear how helpful you would find it, but for maximum debug information you could add -D all to your find command, before the starting-point list.
- Can
-name, -path live on the same command line (need cases, examples, explanation) or they mutually exclusive? Or can we say
-path extended version of -name?
Yes, of course they can be used together, and occasionally it even makes sense to combine them. But the points that may have confused you are that
- they are independent, and
-path tests the whole path, not just the directory part. Perhaps this is what you mean when you ask whether -path is an extended version of -name.
Your attempt at combining them failed because your -path predicate does not actually match the files you want to select. But this would work:
find ${path} -path "*/a/*" -name "script.*.sh"
Also, combinations that use the -o connective (meaning "or") instead of default or explicit -a ("and") may find more use, or combinations in which one or both of the predicates is negated via -not.
It worksyet, I'm wrong? .... AGAIN? Sorry, what planet are you from?why, and you commenthere is worked variant....but unfortunately the comment answer no one questions...and...Please, read all questions carefully again.... Unfortunately I will not be able to give you more understandable explanation, if you will not understand this explanation. Sorry. p.s. I'm from Earth and you? :)