Search code examples
linuxbashcommand-linels

Listing all files in directory with .bar extenion but not .foo.bar extension


I want to use the ls command to list all files in directory a with .bar extension but not .foo.bar extension. The following picks up .foo.bar files which I don't want

ls -l some/path/*.js

Must be simple. I just need an AND and NOT in there somehow.


Solution

  • Using bash pathname expansion with [ pattern matching, you can write:

    ls -l some/path/*[!(.foo)].bar