Re: how to use find ?

 
xujun
Advisor

how to use find ?

What is the difference between :
find . -name "a*"
and
find . -name a*
?

and how to find a file under current directory but no including sub directory?
10 REPLIES 10
Thierry Poels_1
Honored Contributor

Re: how to use find ?

hi,

find . -name "a*"
--> find will search for files starting with "a"

find . -name a*
--> command line interpreter will expand "a*" to all files starting with "a" in current directory BEFORE executing the find commmand, so very probably NOT what you want.


to search files ONLY in current directory: how about using "ls" ;-)


regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Arturo Perez del Galleg
Frequent Advisor

Re: how to use find ?

Alexander M. Ermes
Honored Contributor

Re: how to use find ?

Hi there.
Sorry for bothering, but did you try the manpages ?
Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Steven Sim Kok Leong
Honored Contributor

Re: how to use find ?

Hi,

For the default bourne shell (/sbin/sh), no difference between find with double-quotes or find without double-quotes.

# echo $SHELL
/sbin/sh
# find / -name "aaa*" -print | wc -l
97
# find / -name aaa* -print | wc -l
97

No difference in default bash shell as well:

# bash
bash-2.05a# find / -name "aaa*" -print | wc -l
97
bash-2.05a# find / -name aaa* -print | wc -l
97

No difference in korn shell as well:

# ksh
# find / -name "aaa*" -print | wc -l
97
# find / -name aaa* -print | wc -l
97

Hope this helps. Regards.

Steven Sim Kok Leong
Niraj Kumar Verma
Trusted Contributor

Re: how to use find ?

There will be no diffrence in theresult.

-Niraj
Niraj.Verma@philips.com
Steven Sim Kok Leong
Honored Contributor

Re: how to use find ?

Hi,

Note that for Linux and Solaris, you need to use double-quotes in your search term, otherwise your find will not work.

Hope this helps. Regards.

Steven Sim Kok Leong
Carlos Fernandez Riera
Honored Contributor

Re: how to use find ?

It depends:

Is the same if there is not filename like a*

but is not the same if antonio and alberto file exists. This will find alberto and antonio files in each directory from .
unsupported
Steven Sim Kok Leong
Honored Contributor

Re: how to use find ?

Hi,

Carlo is right.

find / -name aaa* works like find / -name "aaa*" only when no file starting with aaa exists in the / directory. If /aaaxyz exists, then the find will fail because it only searches for file(s) named aaaxyz.

find / -name "aaa*" will work regardless of whether /aaaxyz exists or not and search for files starting with aaa.

# ls /aaa*
/aaaxyz
# find / -name aaa* -print | wc -l
1
# find / -name "aaa*" -print | wc -l
98

Hope this helps. Regards.

Steven Sim Kok Leong
Luca Fasolo
Occasional Advisor

Re: how to use find ?

In reply to:
how to find a file under current directory but no including sub directory?

If you are on Linux:
find . -maxdepth 1 -name "*.txt" -print

AFAIK, hp's find doesn't have -maxdepth,
you could use some kind of regular expression
(i.e. for my example, write a regexp for
"find all files whose name contains
only one "/" and contains the string ".txt")...
I think that the best solution (as suggested
by Thierry) is to use ls.

Hope this helps
--Luca