4

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?

  • 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
12

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

  • 1
    Thank you. It works find ~/projects -path "*/trunk*/config/*.xml" – Loom May 17 '13 at 13:41
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
  • 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 9: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 9:44
  • You might want to have a look at oh-my-zsh or my zshrc. – phunehehe May 20 '13 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.