Operating System - HP-UX
1752798 Members
6005 Online
108789 Solutions
New Discussion юеВ

What is the difference between ' find . -name h* ' and ' find . -name ho* '?

 
SOLVED
Go to solution
May_3
Advisor

What is the difference between ' find . -name h* ' and ' find . -name ho* '?

Hi,

The result are different when I type in the command line as follows:
# find . -name h*
find: missing conjunction
# find . -name ho*
./hosts
./net/ticlts/hosts
./net/ticots/hosts
./net/ticotsord/hosts

Could anybody give me an explaination about the difference and why?
Thanks a lot!

Best Regards.,
May
May
5 REPLIES 5
Deepak Extross
Honored Contributor

Re: What is the difference between ' find . -name h* ' and ' find . -name ho* '?

May,
find . -name "h*"
should work.
Deepak Extross
Honored Contributor
Solution

Re: What is the difference between ' find . -name h* ' and ' find . -name ho* '?

If you're curious about why you got the "missing conjunction" error, try this:

set -x
find . -name h*
set +x

You'll probably find that the shell expanded the h* to one or more matching files in the current directory, hence this error.
If you had one or more files starting with "ho" in the current directory, 'find . -name ho*' would also have given the same error.

Another solution to your problem would be:
set -f
find . -name h*
set +f

'set -f' instructs the shell to turn off file globbing
Tore_1
Regular Advisor

Re: What is the difference between ' find . -name h* ' and ' find . -name ho* '?

Hi, if you fail to quote h*, the shell will try to expand it before giving it to the program find.

In my /tmp catalog, this meant find . -name h* was expanded to find . -name hei hei.txt heidu help.sh hh home.chk hpufl1

This makes no sense to the program find. If you quote ("h*") the argument is unexpanded and correctly interprated by find.



Trond Haugen
Honored Contributor

Re: What is the difference between ' find . -name h* ' and ' find . -name ho* '?

Your problem is WHEN the expression is expanded. If what you want to fo is find files starting with h or ho you shhould write:
find . -name h\*
find . -name ho\*

The expression will them be expanded "as find finds files". As opposed to hatched with files in current dir before starting the find.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
hpuxrox
Respected Contributor

Re: What is the difference between ' find . -name h* ' and ' find . -name ho* '?

I "ALWAYS" put qoutes around my search field when im using wildcards like *.

find . -name "h*"

and

find . -name "ho*"