Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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  
share|improve this question

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

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

    
do ls "Night of the Living Dead (1968)"/*rar –  nos Nov 10 '11 at 12:43
add comment

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.

share|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 '12 at 19:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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