-1

I noticed a strange behaviour with linux find utility

Here is my directory structure:

[root@machine test]# ls -lR
.:
total 4
drwxr-xr-x. 3 root root 4096 Aug  1 21:25 dir1

./dir1:
total 8
drwxr-xr-x. 2 root root 4096 Aug  1 21:24 dir2
-rw-r--r--. 1 root root   11 Aug  1 21:25 mgmt.py

./dir1/dir2:
total 8
-rw-r--r--. 1 root root  11 Aug  1 21:24 mgmt.py
-rw-r--r--. 1 root root 106 Aug  1 21:24 mgmt.pyc

If I try to find mgmt.pyc from top directory, I can see it in results

[root@machine test]# find . -name mgmt*
./dir1/mgmt.py
./dir1/dir2/mgmt.py
./dir1/dir2/mgmt.pyc

However, if I try to find it from one level below, it does not show up in results

[root@machine test]# cd dir1/
[root@machine dir1]# find . -name mgmt*
./mgmt.py
./dir2/mgmt.py

Am I using find in an incorrect way or is it some other error?

shriroop_
  • 775
  • 6
  • 15

1 Answers1

2

Wildcards are expanded by the shell if there are any matching names. In the dir1 subdirectory there is a file called mgmt.py, so

find . -name mgmt*

is expanded to

find . -name mgmt.py

before find is started. That's why it only looks for files called mgmt.py exactly.

To prevent the shell from expanding wildcards, just quote them:

find . -name 'mgmt*'
melpomene
  • 84,125
  • 8
  • 85
  • 148