0

With bash, I used to executed ls *.JPG to list all JPG files of a directory, but since macOS suggested me to move to zsh, this simple command doesn't work anymore and gives me the following error:

$ ls *.JPG      
ls: illegal option --  
usage: ls [-@ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]

What the appropriate equivalent with zsh ?

  • Globbing (ie. ls *.JPG) should work in zsh. Remember it's case sensitive, so you may need ls *.jpg. If you want to change back to bash, here are the instructions: https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/ – moo Apr 11 '20 at 21:46
  • 1
    I have plenty of images which extension is upper case JPG, but ls *.JPG returns ls: illegal option -- and usage: ls [-@ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]. – DevonDahon Apr 11 '20 at 21:50
  • @Mark I'd prefer to give zsh a try before decided to change back or not to bash. I just updated my question. – DevonDahon Apr 11 '20 at 21:58
  • 6
    You probably have a filename that starts with a hyphen ... try ls -- *.JPG – Jeff Schaller Apr 11 '20 at 22:07
  • Thanks! That was my problem indeed. – DevonDahon Apr 11 '20 at 22:08
  • Suggesting a duplicate of https://unix.stackexchange.com/q/87355/117549 – Jeff Schaller Apr 11 '20 at 22:27
  • Should rather be ls -d -- *.JPG, or print -rC1 -- *.JPG (zsh) as there's no point calling ls if it's just to print the arguments. – Stéphane Chazelas Apr 12 '20 at 07:46

0 Answers0