I am learning Linux Basics and I have found some unexpected behaviour

Here is the script

ls /home/shiv/Documents

Now, I want to use globbing

cd /home/shiv/Documents
ls *txt 

But, If I want to search for .jpg files as well then, I am getting an error

cd /home/shiv/Documents
ls *{txt, jpg} 
ls: cannot access '*{txt,': No such file or directory
ls: cannot access 'jpg}': No such file or directory

What is the right command to list both txt and jpg files?


You can do

ls *{txt,jpg}

spaces are used to separate arguments, so the shell is treating *{txt, and jpg} as two arguments, trying to match them separately. { and } are treated literally instead of expanded to a range of possible matches.

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.