Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to look for all XML files in a particular directory and all sub-directories (recursively) inside it.

ls -R *.xml is only listing files in the current directory. I am quite sure, the sub-folders themselves have several .xml files, but none are showing up.

Is this a configuration issue?

share|improve this question

4 Answers 4

up vote 10 down vote accepted

Try using Find

sudo find . -print | grep -i '.*[.]xml'
share|improve this answer
is the sudo must, or it's there to ensure super user privileges? –  Shamim Hafiz Jun 13 '13 at 20:36
I let you decide. Sudo, No Sudo. –  Mitch Jun 13 '13 at 20:44
If this answered your question, you may mark this answer as accepted. –  Mitch Jun 13 '13 at 21:57
Just out of interest. What is the advantage of find over ls -R? –  don.joey May 22 '14 at 9:21
@don.joey This might help stackoverflow.com/questions/13830036/… –  Mitch May 22 '14 at 10:08

You can do it with find only:

find . -name '*.xml'

. is the current directory. If you need to search in another directory, replace . with the directory path.

share|improve this answer
Does it search for the required file recursively in the directory rooted at current directory. In my case it just checked in the current directory only, didn't check the subdirectory. –  mostafiz Sep 30 '14 at 20:24
@mostafiz, you need to quote the '*.xml' part. I'll edit my answer. –  KaeruCT Oct 1 '14 at 14:39
Actually I searched for .php files in current directory. But it returned only .php files in current directory, didn't searched recursively in sub-directories. That's why I'm asking whether find command searches recursively or not. –  mostafiz Oct 1 '14 at 16:52
@mostafiz, the find command searches recursively. If you don't quote the parameter, I think your shell might do an expansion on the *, so it will match the files in the current directory. –  KaeruCT Oct 1 '14 at 19:38
All right! May be I'd made some mistake. Now it is working perfectly! –  mostafiz Oct 2 '14 at 14:02

Try this command:

ls -R | grep '.*[.]xml'

ls doesn't have options to filter the output. For that you would need to use pipe. This passes the output from ls to grep, which then filters them to show just the .xml files.

share|improve this answer

This would work too.

find /path-dir -type f | xargs grep *.xml

share|improve this answer

Your Answer


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.