how can I list all the files from the current directory, whose names start with abc and have their 3rd and 4th letters either 'x' or 'y'?

Please help.

  • 4
    That list is empty, surely? if the name starts with abc then the 3rd letter cannot be x or y Apr 4, 2018 at 12:48
  • 1
    Can you clarify - are you looking for all files that start with 'a' or 'b' or 'c' with a 3rd and 4th letter both either 'x' or 'y' ? Perhaps give examples of the filenames you expect to match and not match Apr 4, 2018 at 12:49
  • 2
    The question in the title doesn't match the question in the body. Please clarify what you want? (And perhaps try something yourself, it's probably rather simple) Apr 4, 2018 at 12:52

3 Answers 3


I'll assume the "3rd letter" part is a typo since you're also saying it should be "c".

ls -l abc[xy]*

The question is ill defined, however you can use bash/sh globs for ls like

ls abc[xy][xy]*

or if you need something more complex you can utilize the power of regexps. For example with (e)grep :

 ls  |  egrep "^abc(x|y){2}" | xargs -d\\n  ls -l

regexps are quite powerful, you probably will be able to do what you like.

  • ls abc[xy][xy]* worked. Thanks a lot everyone.
    – Vaibhav
    Apr 4, 2018 at 16:01

If i understand this guy correctly, then this is what he is looking for.

find ./ -name "abc[m]*"

or this way find ./ -name "ab[x][y]*"

  • local directory is the default for find. (find -name ... is just fine)
    – goteguru
    Apr 4, 2018 at 13:02
  • @goteguru Possibly for find on Linux...
    – Kusalananda
    Apr 4, 2018 at 13:03
  • @goteguru Personally just used to the giving it a directory part. As i mostly look for files in other folders. barely in the same ones. Just something im used to :)
    – TheSebM8
    Apr 4, 2018 at 13:05
  • Yeah, it's for gnu. You must type the dir if you use osx or something archaic/rigidly standard compliant. I didn't say there is problem, it was just a hint if you are using gnu. :)
    – goteguru
    Apr 4, 2018 at 13:16

Not the answer you're looking for? Browse other questions tagged .