1

When I have a nested directory find . -name "*.py" -print command gives me all the python scripts beneath current directory. However, find . -name *.py -print returns only the python scrips in current directory.

Is this expected behavior? What makes this difference? I use Mac OS X 10.7.

prosseek
  • 8,558

2 Answers2

5

It's probably not the same command. You could put echo in front to check.

$ echo find . -name "*.py" -print
find . -name *.py -print

$ echo find . -name *.py -print
find . -name foobar.py barfoo.py -print

Without quotes, the shell expanded *.py, so find gets different arguments, which yields different results.

You should always quote * when you want a command to see * literally. Otherwise the behaviour will be erratic (the command works as long as there are no *.py files for the shell to expand to).

frostschutz
  • 48,978
2

Because the shell expands the wildcard when you don't protect the pattern.

You always have to use some quotes.

jordanm
  • 42,678