On Linux,
cd /tmp
mkdir foo; cd foo
Now, running
find . -name 'foo'
gives no output. Whereas running
find /tmp/foo -name 'foo'
Gives the output /tmp/foo
which doesn't make sense to me. Can somebody explain
why?
Thanks in advance!
There is no normalization of the command line arguments before the tests are applied. Thus the results differ depending on the used path (if symlinks are involved):
In "your case" both calls would give the same result which might be (more) confusing. You can use |
|||||
|
There is no object named You are correct with assuming that
|
|||||||||||||||||
|
And
It so happens that |
|||
|
(gnu) find shows any matches found within the path provided to the command because it starts its comparison with the commandline arguments, descending deeper into the directory structure from there (thus,
While this behavior may not be expected or appear intuitive from a user perspective (and yes, it had me confused at first as well), it does not constitute a bug but corresponds with the logic and functionality described in the man and info pages for (gnu) find. |
||||
|
./
it didn't matchfoo
– Costas 11 hours agofind
. – York 11 hours agobar
that points to a filefoo
which is outside the search path. Shall that match or not? – Hauke Laging 10 hours ago.
and/tmp/foo
are not the same - they are two different hard links to the same directory;find /tmp/foo/. -name 'foo'
doesn't find anything either. – jimmij 10 hours agofind /tmp/foo -name 'foo'
, I was asking bash to find in the directory/tmp/foo
, a file whose name is "foo". Because the directory/tmp/foo
is empty, it should have returned nothing. I don't understand why it returns/tmp/foo
. On the other hand, when I runfind . -name 'foo'
, I was asking bash the same thing, i.e., finding a file in the current directory (which happened to be/tmp/foo
), whose name is 'foo', and it returns nothing which makes sens. – York 10 hours ago