I'm trying to list all files in /etc that has only 2 characters before the first period, and not include sub-directories and their content.

I'm using:

ls -d ??.*

and it is working just as I want, but when I try to do it from another directory I can't get it to work. I have tried

ls -d /etc ??.* 


ls -d ??.* /etc

But I get the same error

ls: cannot access ??.*: No such file or directory

This is for a school assignment, so using find or anything other than ls is not an option. Thanks in advance!

  • Please check the man pages before posting a question. I believe it clearly explains that -d has a different purpose.
    – Bram
    May 5, 2017 at 11:15
  • 1
    @Bram, if any of the ??.* are directories, -d does prevent listing their contents. Though of course, it still lists the directories themselves. But since this was a school assignment, I'm not sure if it's necessary to work around that, at least with the level of accuracy usual to unix.SE. :)
    – ilkkachu
    May 5, 2017 at 11:54

1 Answer 1


ls does not take a separate directory argument.

To match files in a specific directory, you can simply prepend the directory path to your glob pattern:

ls -d /etc/??.*
/etc/ld.so.cache  /etc/ld.so.conf  /etc/ld.so.conf.d  /etc/rc.local
  • @PerKristianPettersen If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites.
    – terdon
    May 5, 2017 at 11:20

You must log in to answer this question.

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