7

I need to find all xml-files that are placed in folders named config. Also config must be somewhere under a folder named trunk. 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?

phunehehe
  • 20,030
  • 27
  • 99
  • 151
Loom
  • 3,863
  • 11
  • 30
  • 44
  • You do need `-regex` if you want to make sure that only files from a directory `config` are returned unless you can guarantee that no directory `config` has subdirectories (which have a `*.xml` in their tree). – Hauke Laging May 17 '13 at 13:53

2 Answers2

13

That's not a regex. For globs one should use the -path predicate instead.

Ignacio Vazquez-Abrams
  • 44,857
  • 7
  • 93
  • 100
3

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
phunehehe
  • 20,030
  • 27
  • 99
  • 151
  • Actually, 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 example `ls ~/projects '**/trunk/**/config/*.xml' --recursive`) but without success. – Loom May 20 '13 at 09:30
  • 1
    Ah I forgot, `zsh` doesn't do much with the default settings, you need to put `setopt EXTENDED_GLOB` in `~/.zshrc`. – phunehehe May 20 '13 at 09:44
  • You might want to have a look at [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) or [my zshrc](https://github.com/phunehehe/terminal-dotfiles/blob/master/_zshrc). – phunehehe May 20 '13 at 09:46