From the following results it appears the *.rar is being taken literally, and not expanded. man glob gives no detail as to how it expands. Would someone kindly explain why?

~/Films $ls "Night of the Living Dead (1968)/"  
Night_of_the_Living_Dead_1968.par2        Night_of_the_Living_Dead_1968.part23.rar.1  
Night_of_the_Living_Dead_1968.part01.rar  Night_of_the_Living_Dead_1968.part24.rar  
...

~/Films $ls "Night of the Living Dead (1968)/*.rar"  
ls: cannot access Night of the Living Dead (1968)/*.rar: No such file or directory  
~/Films $ls "$(pwd)/Night of the Living Dead (1968)/*.rar"  
ls: cannot access /home/g/Films/Night of the Living Dead (1968)/*.rar: No such file or directory  
~/Films $ls "Night of the Living Dead (1968)/*rar"  
ls: cannot access Night of the Living Dead (1968)/*rar: No such file or directory  
link|improve this question

0% accept rate
do ls "Night of the Living Dead (1968)"/*rar – nos Nov 10 '11 at 12:43
feedback

migrated from stackoverflow.com Nov 11 '11 at 2:42

This question came from our site for professional and enthusiast programmers.

1 Answer

A * inside single quotes is treated literally. So you need to put only the directory name that has spaces in it, in quotes:

ls "Night of the Living Dead (1968)"/*.rar  

A * inside double quotes is expanded by the shell.

link|improve this answer
1  
A * inside single quotes is treated literally. A * inside double quotes is expanded as a glob. – William Pursell Nov 10 '11 at 14:19
apologies--I was thinking the OPs issue was that ls was set to a function or an alias that was munging the quotes; but in fact it is my function that was causing "*" to expand! I cannot remove the downvote unless you edit your answer. – William Pursell Nov 10 '11 at 14:30
An easier way to do this interactively is ls Night[TAB]/*.rar; let the shell complete the directory name rather than typing it out. The shell's tab completion will insert backslashes as necessary to escape any special characters. – Keith Thompson Mar 13 at 19:48
feedback

Your Answer

 
or
required, but never shown

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