这是一个好奇心,但我注意到/etc/httpd/logs被链接到/var/log/httpd ,但是当我在/etc/httpd/logs里面,并且我做ls -la我看到:
drwx------ 2 root root 4096 Mar 21 14:58 . drwxr-xr-x 9 root root 4096 Mar 17 03:10 ..
为什么没有. 进入显示lrwx.... ?
但是,当我去/etc/httpd和ls -la我看到:
lrwxrwxrwx 1 root root 19 Mar 4 17:12 logs -> ../../var/log/httpd
我可以回答一个问题吗? 假设你在RedHat / CentOS上安装…
ls /etc/httpd/ # should return something like: # conf conf.d logs modules run cd /etc/httpd/logs/ # Why does this next command fail? ls ../conf # ls: cannot access ../conf: No such file or directory # But this next command works? cd ../conf
简短的回答是当你在/etc/httpd/logs (符号链接)里面的时候,你实际上在/var/log/httpd目录下。
cd /etc/httpd/logs/ pwd # /etc/httpd/logs pwd -P # /var/log/httpd
. 表示当前目录。 一旦你cd到一个符号链接,你在目标目录。 你所看到的并不是一个错误,也不是一个问题。 这是符号链接在UNIX系统中的工作方式。 如果您希望在列出文件时查看符号链接,请保留在实际符号链接所在的父目录中。
默认情况下, cd将“跟随”符号链接,但是它会使用/etc/httpd/logs设置PWD系统variables。 这样,当你做cd ..它使用PWDvariables作为参考。 ls不会的 它抓取(/ var / log / httpd)所在的物理位置,就像/bin/pwd但shell内buildpwd使用$ PWDvariables。
所以当你进入/ etc / httpd / logs时,你实际上去了/ var / log / httpd。 这就是为什么当你做ls -la ,你会发现。 作为目录而不是符号链接。 然后当你使用cd退出时,它会记住你在/ etc / httpd中,并用它作为参考。
如果执行cd -P /etc/httpd/logs ,-P表示“物理”,则可以看到cd将PWD设置为/ var / log / httpd。
(对不起,我的回答是你的问题和jscotts问题的混合)