'find' (command) finds nothing with -wholename

12.9k Views Asked by At

Why does this command work:

/home/user1/tmp $ find ./../.. -wholename '.*/tmp/file.c' -exec echo '{}' \;
./../../user2/tmp/file.c
/home/user1/tmp $

And this command does not work? (finds nothing)

/home/user1/tmp $ find /home -wholename '.*/tmp/file.c' -exec echo '{}' \;
/home/user1/tmp $
1

There are 1 best solutions below

1
On BEST ANSWER

The first command generates file names starting with ./../... Thus the wholename pattern will match because they start with ..

The second command generates filenames starting with /home. However, the wholename pattern is still looking for paths starting with . which will not match any file in this case.

Note that patterns are not regular expressions. If you were expecting them, look at the -regex option instead.