fishyfriend
fishyfriend

Reputation: 196

Why does GNU Find care about a trailing slash in this situation?

Given:

When I enter the following command, I see no results:

find /path/to/repos/myrepo -name .git -prune -o -path '/path/to/repos/myrepo/*' -newermt '2020-05-18 15:52:34' -print

Yet when I add a trailing slash to the starting point,

find /path/to/repos/myrepo/ -name .git -prune -o -path '/path/to/repos/myrepo/*' -newermt '2020-05-18 15:52:34' -print

the command prints /path/to/repos/myrepo/.

Why this difference?

Upvotes: 2

Views: 614

Answers (1)

fishyfriend
fishyfriend

Reputation: 196

GNU Find preserves the starting-point as entered, so in the first example, /path/to/repos/myrepo doesn't match -path '/path/to/repos/myrepo/*' because the path expression includes a trailing slash and there is no trailing slash in the directory name.

In the second example, since the directory name does include a trailing slash, it successfully matches the path expression /path/to/repos/myrepo/*.

The -newermt test is irrelevant here. Note that the other paths processed by find in these examples are identical, regardless of whether the starting-point contained a trailing slash. I.e., if myrepo contains a file xyz, it is processed as /path/to/repos/myrepo/xyz in both cases. In other words, for subpaths of the starting-point, a trailing slash is appended to the starting-point if needed; this just doesn't apply to the starting-point itself.

Upvotes: 3

Related Questions