listing files with spaces, using wildcard

steve steve at lonetwin.net
Fri Feb 20 02:04:40 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.
Surrounding the expression with single quotes won't work, because the shell 
meta-character expansion is ignored. However, what is it that you are trying to 
achieve ?

listing works just fine without the quotes:

[steve at laptop foo]$ ls *foo*dog
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
[steve at laptop foo]$ ls -1 *foo*dog
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
[steve at laptop foo]$

...if the files are in different directories, use find:
[steve at laptop foo]$ find -type f -name "*foo*dog"
./a/1foo_ aa_bb_cc.dog
./a/4foo_aa_bb_cc.dog
./a/6foo_aa_bb_cc.dog
./a/5foo_aa_bb_cc.dog
./b/3foo_aa_bb _ccc.dog
./b/2foo_aa_bbbb_cc.dog
[steve at laptop foo]$

However, I have a feeling, you need to do something more than just listing. What 
do you need ?

cheers,
- steve

-- 
Linux Centric Marketplace: http://www.tuxcompatible.com




More information about the fedora-list mailing list