0

I'm connected to a CentOS server through SSH from macOS. When I try to find with a wildcard at the beginning, it seems to only search the current directly, no recursion. But if I put the wildcard at the end of the filename, it works. I don't have this problem on the local Mac.

# find . -name *.inc
./copra_xml_gen.settings.inc
#
# find . -name auth.inc
./common_v4/auth.inc
./v5_old/common/auth.inc
./common/auth.inc
./v6/common/auth.inc
./v5/common/auth.inc
#
# find . -name auth*
./common_v4/auth.inc
./v5_old/common/auth.inc
./common/auth.inc
./v6/common/auth.inc
./v5/common/auth.inc
Elliott B
  • 1,347
  • 5
  • 17
  • 44

1 Answers1

2

The shell is performing filename expansion before invoking find. See https://www.gnu.org/software/bash/manual/bash.html#Shell-Expansions

You want to protect the pattern from the shell:

find . -name '*.inc'

or

find . -name \*.inc

In your current directory:

  • you have a file that matches *.inc and the shell replaces that word with the actual filename in your find command.
  • you do not have a file that matches auth*, so the pattern is not replaced.
glenn jackman
  • 27,524