[KLUG Members] Find command fails when searching only for mp3s
Jamie McCarthy
jamie at mccarthy.vg
Tue Mar 28 07:47:09 EST 2006
bruce at armintl.com (Bruce Smith) writes:
> > > [steve at rosie ~]$ find ~/Desktop/aFewFiles/ -name *.mp3
> >
> > Try: find ~/Desktop/aFewFiles/ -name "*.mp3"
>
> No, you need SINGLE quotes around the expression (not double).
Steve, what is happening is a result of how the command line expands
wildcards. This is a general principle worth understanding.
When you use a wildcard in a command line, it gets expanded before
processing begins on the line. So, suppose you're in a directory
with the files
foo1
foo2
foo3
bar
and you type
mv foo* bar*
The "foo*" expands to a list of all the files in that directory that
match that pattern, and so does the "bar*". THEN mv is invoked and
passed that command line. So it's exactly the same as if you typed
mv foo1 foo2 foo3 bar
which may or may not be what you intended.
This is true for every unix program. Since the command line is in
control of this expansion, it's no use asking why mv doesn't treat
the wildcards more like what you might expect 'mv foo* bar*' to do --
mv never even sees the wildcards.
So when you saw
[steve at rosie ~]$ find ~/Desktop/aFewFiles/ -name *.ogg
/home/steve/Desktop/aFewFiles/4.ogg
what must have happened was that there was a file in your ~ directory
named 4.ogg. You can look at the files in ~ and figure out the
command line expansion yourself :)
--
Jamie McCarthy
http://mccarthy.vg/
jamie at mccarthy.vg
More information about the Members
mailing list