Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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 Answers 2

up vote 8 down vote accepted

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

share|improve this answer
    
Thank you. It works find ~/projects -path "*/trunk*/config/*.xml" –  Loom May 17 '13 at 13:41

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
share|improve this answer
    
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
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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