Search code examples
unixfile-listing

List out the required files from an Unix directory


I have files in a unix directory as shown below

XMP.df.a.xml
XPL.dg.a.xml
XMP.sf.b.xml
XPL.ba.b.xml
XMP.ad.c.xml
XPL.lk.b.xml

I have to list out the files that have both "XMP" and "b" in its name.

I tried ls -ltr XMP* *b* But it displays all the 'XMP' as well as 'b' results.

Is there a way to list only the files that has XMP and b in it's name? Thanks in advance.


Solution

  • The space is causing you headaches. What you have right now is asking ls to look for two different sets of files; XMP* and *b* in the current directory. What you want is:

    ls -ltr XMP*b*
    

    No space.