I have a directory with files of all kinds and I wanted to use the ls command to list all of them, except those with a name that ends in .config, but I do not get how to do it.


As in the related post, in bash set extended globbing then ask ls for those files that don't end in .config:

shopt -s extglob
ls -d -- !(*.config)

By default, files that start with a period (dot, .) are not shown; you can see them by enabling another shell option:

shopt -s dotglob
  • 2
    Nitpicking: This is not using ls to do anything special, but it's using the shell's file name expansion to give the correct list to ls. The ls utility is still used as it's always been used. This does not matter much unless one cares about how things actually happen (ls does not expand globs). – Kusalananda Feb 12 '19 at 20:26
  • You have to squint to read it with my interpretation : that I'm asking ls to list these files; you're correct that ls is not expanding anything. – Jeff Schaller Feb 12 '19 at 20:27
  • "My eyes are old and bent." – Kusalananda Feb 12 '19 at 20:29
  • what @Kusalananda is saying is very important. It will save you life some day. Well may be save your life, but it will definitely save you from a lot of problems. – ctrl-alt-delor Feb 12 '19 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.