4

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 $
Reinstate Monica Please
  • 11,123
  • 3
  • 27
  • 48
DrBeco
  • 11,237
  • 9
  • 59
  • 76

1 Answers1

12

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.

Diego
  • 1,789
  • 10
  • 19
  • Great! Thanks! To be perfect, add this to your answer: `root@camel:/home/user1/tmp# find /home -wholename '*/tmp/file.c' -exec echo '{}' \;` – DrBeco Jun 13 '15 at 16:51