Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 24 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… – 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
Anyway to get this to show the directory it came from? – ashkan Jul 28 '15 at 20:55

1) Go to the root directory. 2) Execute find -name *.xml

This will list all the files along with dir path containing .xml files

share|improve this answer

This would work too.

find /path-dir -type f | xargs grep *.xml
share|improve this answer
This doesn't find files whose names match *.xml. It finds files containing the text *.xml ...provided no .xml files are present in the directory from which the command is run. (If there are, the shell replaces *.xml with a list of those files in the current directory, passing them to grep and causing the first filename to be taken as a search pattern to match in the subsequent filenames and in the files whose names are passed to grep from find via xargs.) Writing \*.xml prevents shell expansion but even then this command still doesn't do anything like what is intended. – Eliah Kagan Apr 3 '15 at 13:24

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.