Operating System - HP-UX
1847249 Members
2865 Online
110263 Solutions
New Discussion

Re: Find Command Not Finding Files

 
SOLVED
Go to solution
Monte Heeren
Frequent Advisor

Find Command Not Finding Files

Logged on as user root.
Directory contents:
/ifas/bsi/setup/perm/SPFMAPCK
/ifas/bsi/setup/perm/SPFMARBL
/ifas/bsi/setup/perm/SPFMARIN
/ifas/bsi/setup/perm/SPFMARSI

Command:
find / -name SPFMA*

The results:
/ifas/bsi/setup/perm/SPFMARIN.

Only 1 file is returned.

Do not understand why the find command will not return all 4 SPFMA* files. If I use
find / -name "SPFMA*", all 4 file name will be returned.

Why does find / -name SPFMA* only return one file?

Monte Heeren.
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: Find Command Not Finding Files

This is a case of that stupid computer doing exactly what you are telling it too. The shell is expanding the '*' and you wantr find to do it. Essentially it's finding only SPFMARIN because that file is found in your current working directory.

find / -name 'SPFMA*'

will do what you want because the quotes prevent the shell from expanding the metacharacter.

Also, you should avoid find from / because those can be very expensive operations.
If it ain't broke, I can fix that.
Monte Heeren
Frequent Advisor

Re: Find Command Not Finding Files

Thank you for the response A. Clay.

You were right. There was a file in my root directory called SPFMARIN. The result of the command only looked for the file
SPFMARIN in other directories. Its like it stopped matching after if found the first match in the root directory.

I'm still confused.

When using the command:
find / -name SPFMA*

if a file matches this expression in the
root directory, the shell will stop
matching file names and will continue to
find only that file in other directories?


Monte.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Find Command Not Finding Files


This should make it clearer:

Let's suppose that in your current working directory (it does not matter about the directories listed in the pathname list of the find command) you have the files "dogbone", "doggone", and "doghouse".

When you enter:

find / -name dog*

what the find command actually sees after the shell expands the '*' metacharacter
is:

find / -name dogbone doggone doghouse

and this,in fact, is a syntax error for find because -name expects exactly one argument.

If your current working directory only has the file "dogbone" in it then when you entered the same command find would actually see (with the same input as the first example):

find / -name dogbone

In this case, -name is supplied with exactly one argument so that it is not a syntax error but the ONLY file that fine will match is "dogbone".

Now, consider the case of

find / -name "dog*"

In this case, regardless of the contents of your current working directory, what find sees is:

find / -name dog*

but notice that now the '*' is actually supplied to find itself so that it can do the pattern match. Any file in any directory that begins with "dog" is now found.

You problem stems not from not understanding how the find command works but rather from not understanding how the shell works.
If it ain't broke, I can fix that.
Monte Heeren
Frequent Advisor

Re: Find Command Not Finding Files

A. Clay.
I understand now! Thank you for explaining it to me. I need to understand that the shell has a mind of its own!


Monte.
Monte Heeren
Frequent Advisor

Re: Find Command Not Finding Files

A. Clay has found the answer for me.