listing files with spaces, using wildcard

Phil Meyer pmeyer at themeyerfarm.com
Fri Feb 20 07:44:11 UTC 2009


bruce wrote:
> hey...
>
> here's one i can't see..
>
> goat a bunch of files in different dirs.. the files might have spaces
>
>  1foo_ aa_bb_cc.dog
>  2foo_aa_bbbb_cc.dog
>  3foo_aa_bb _ccc.dog
>  4foo_aa_bb_cc.dog
>  5foo_aa_bb_cc.dog
>  6foo_aa_bb_cc.dog
>
> i'm trying to figure out how i can do a complete list of all files with
>  *foo*dog
>
> so i get the files with spaces and underlines...
>
> i thought simply doing somehting like
>
>  ls '*foo_*.dog' and surrounding the filename with single quotes would
> work.. but it doesn't.
>
> thoughts/pointers/etc...
>
> thanks
>
>
>   


This is fundamental:

the command: ls, does not take wildcards.
The shell expands wildcards and passes the results to ls.

By quoting the wildcards, you are passing them to ls to interpret, which 
it cannot.

The command, find: DOES accept wildcards for some arguments, like: 
-name.  Thus, you want to pass wildcards to the find command by quoting 
or escaping them.

Also, the shell treats the double quote marks: " differently than the 
single quote marks: ' under certain circumstances.

The 'convention' for quoting is:

double quotes for passing wildcards

single quotes for strings that may contain other characters that the 
shell might interpret.  But even then, it may depend on the command you 
are passing those arguments to.

For example, neither will allow you to pass a minus character, as the 
first character of a pattern match, to grep.

In your original work here, the first line you typed works:
ls *foo*dog
Even with spaces.

Your other attempts using quotes do not work because you are passing the 
wildcards to the ls command, which cannot use them.

Hope this helps!





More information about the fedora-list mailing list