在软链接链接的目录中查找文件

finding files in directories linked to by soft links

ln -s /horribly/long/and/annoyin/path/to/java/jdk java

现在,

$ find java -name "jni.h"
$ cd java && find . -name "jni.h" && cd ..
./include/jni.h

当您不cd访问目录时却找不到该文件,这似乎违反直觉。

这是预期的行为还是我只是使用了错误的命令?

这是预期的,正如 man page 所说:

-P Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.

尝试:

find java/ -name "jni.h"

find -L java/ -name "jni.h"

如:

-L Follow symbolic links. ...