How to find files with a certain subpath?
8,062
Solution 1
That's not a regex. For globs one should use the -path
predicate instead.
Solution 2
I am not sure what you want to do with the files after you find them, but for interactive use in zsh
I would use something like this:
ls **/trunk/**/config/*.xml
Author by
Loom
Updated on September 18, 2022Comments
-
Loom over 1 year
I need to find all xml-files that are placed in folders named
config
. Alsoconfig
must be somewhere under a folder namedtrunk
. For example, I am interested in all files like below:~/projects/e7/trunk/a/b/c/config/foo.xml ~/projects/d/trunk/config/bar.xml ~/projects/trunk/config/other.xml ~/projects/e/e/e/trunk/e/e/e/e/e/e/e/e/config/eeeee.xml
I tried the
find
command:find ~/projects -regex "*/trunk/*/config/*.xml"
, but the output was empty. What is the correct way to find the required files?
-
Hauke Laging almost 11 yearsYou do need
-regex
if you want to make sure that only files from a directoryconfig
are returned unless you can guarantee that no directoryconfig
has subdirectories (which have a*.xml
in their tree).
-
-
Loom almost 11 yearsThank you. It works
find ~/projects -path "*/trunk*/config/*.xml"
-
Loom almost 11 yearsActually, I'd like to look in some files from recieved list. After your answer, I became interested in
zsh
and installed it. But unfortunately you command-line didn't work. I tried to modify your command (for examplels ~/projects '**/trunk/**/config/*.xml' --recursive
) but without success. -
phunehehe almost 11 yearsAh I forgot,
zsh
doesn't do much with the default settings, you need to putsetopt EXTENDED_GLOB
in~/.zshrc
. -
phunehehe almost 11 years