为什么“ls -a”对root用户隐藏了一些现有目录?

Zso*_*kai 2 linux shell filesystems ext3

今天我在我们的一台测试服务器上发现了一些非常有趣的东西(至少对我来说):

我可以使用相对路径从我的实际工作目录切换到现有目录,但是在使用ls -a.

这是shell会话(作为root):

$ pwd
/you/are/here
$ ls -a
. ..                       <-- Note: "somedir" is not shown to root
$ echo $CDPATH

$ cd somedir               <-- But still: "cd" works fine
$ pwd
/you/are/here/somedir
$ cd ..
$ pwd
/you/are/here
$ ls -a
. ..
Run Code Online (Sandbox Code Playgroud)

有人能告诉我,这怎么可能?我已经检查过:lsis from/bin/lspwdis /bin/pwd,都来自他们的原始包(我的意思是:没有被黑)。

/you是挂载的 EMC 磁盘 (ext3)。并且somedir存在,因为我可以列出它的内容(有几个子目录,文件)。它的名字不以点开头。

更多的 shell 会话,以及有关命令和ls输出的更多信息:

root@U-TEST@AT$/bin/ls -ali
total 4
16515074 drwxrwxr-x  2 U8000966 test 2048 Sep  1 07:39 .
16515073 drwxrwxr-x  3 U8000966 test 2048 Apr 27  2006 ..
root@U-TEST@AT$ls -ali somewhere | head -5
total 182
16515075 drwxrwxr-x  43 U8000966 test  2048 Sep  1 07:39 .
16515074 drwxrwxr-x   2 U8000966 test  2048 Sep  1 07:39 ..
16519169 drwxrwxrwx   4 U8000966 test  2048 Jul 25  2007 AAA
16515124 drwxrwxr-x   3 U8000966 test  2048 May 12  2006 BBB
root@U-TEST@AT$type ls
ls is aliased to `/bin/ls $LS_OPTIONS'
root@U-TEST@AT$type pwd
pwd is a shell builtin
root@U-TEST@AT$/bin/pwd
/you/are/here
root@U-TEST@AT$cd somewhere
root@U-TEST@AT$/bin/pwd
/you/are/here/somewhere
root@U-TEST@AT$type cd
cd is a shell builtin
Run Code Online (Sandbox Code Playgroud)

请注意第一个之后的总计 4ls -ali。(不知道有没有关系……)

还有一些测试:

root@UR-TEST@AT$ls
.  ..
root@U-TEST@AT$touch somewhere/testfile
root@U-TEST@AT$ls
.  ..
root@U-TEST@AT$cp somewhere/testfile ./
root@U-TEST@AT$ls
.  ..  testfile
root@U-TEST@AT$du .
2       .
root@URBIS-TEST@AT$
Run Code Online (Sandbox Code Playgroud)

而 EMC 是:http : //www.emc.com/products/family/disk-library-family.htm,但在这种情况下,他们只是一个磁盘提供商,带有硬盘,格式化为 ext3。

更新

(对不起,但昨天我不得不离开)

我确实检查过echo *,它的输出是:. ..。这里是LS_OPTIONS-a -N --color=tty -T 0

我已经检查了 Gilles 提到的 automount 东西,但是当我更改为somewhere并发出mount|grep somewhere时,没有输出。

这里是lsattrstrace输出的建议:http://gist.github.com/566947

Gil*_*il' 5

在我写这篇文章的时候,你还没有排除$LS_OPTIONS. GNU ls 有一些文件忽略选项,ls -I foo -a但仍然忽略foo. 但是我的其余答案假设您在没有$LS_OPTIONS.

total 4事实上,这条线并不令人惊讶。这是.和使用的块总数..。如果.为空且..很小并且位于块大小等于 4 ls 块的文件系统上(这很常见:GNU ls 默认为 1kB 块,而 ext[234] 通常使用 4kB 块),则预期总数为 0 + 1 * 4 = 4。

正在运行的文件系统发生了一些不寻常但并非闻所未闻的事情/you/are/here。当您请求/you/are/here(with opendir()and readdir(3))的内容时,文件系统仅以.and响应..;然而,当你假设/you/are/here/somedir存在时,你会被告知它确实存在。这是令人惊讶但可能的行为。

一个可能但极不可能的解释是一个恶魔(如麦克斯韦的恶魔,而不是守护程序),somedir它会在您访问它时移动到位,并在您列出目录时将其移开。因此,您观察到的特殊性可能是由一个恰好做出正确猜测的普通程序引起的,它并不表示操作系统有任何问题。

事实上,操作系统可能行为以一种特殊的方式。一个常见的罪魁祸首是自动安装系统。自动挂载系统的工作方式通常是这样的:

  • 例如/you/are/here,一个目录被设置为安装点的位置。一个特殊用途的文件系统(可能称为autofs)安装在那里。

  • 例如,当您尝试访问 中的条目时/you/are/here/you/are/here/somedir文件系统驱动程序会尝试挂载somedir文件系统。例如,它可能会在其配置文件中查找类似somedir = /dev/foo或的行somedir = server:/loca/tion,并将指示的设备或 NFS 位置挂载为/you/are/here/somedir.

  • 当您列出目录时/you/are/here,您会看到当前安装的每个文件系统的子目录。

  • 当您停止使用 时/you/are/here/somedir,可能在延迟之后,自动挂载程序会卸载somedir。所以somedir不再出现在/you/are/here.