Why*_*rrh 2 unix linux directory
首先,举个例子:
~ $ ls
~ $ mkdir foo; cd foo
foo $ pwd
/Users/person/foo
foo $ ls
foo $ touch file1 file2 file3
foo $ ls
file1 file2 file3
foo $ rm *
foo $ ls
foo $ rm -r ../foo
foo $ pwd
/Users/person/foo/
foo $ touch file4
touch: file4: No such file or directory
foo $
Run Code Online (Sandbox Code Playgroud)
当您删除当前所在的目录时会发生什么?为什么我仍然在一个不存在的目录中(我认为它不存在仅仅是因为我无法写入它)?我想这与某种指针有关。
您的 shell 进程将该目录作为其当前目录,该目录将其 inode 保留在磁盘上,其分配方式与打开的文件在取消链接后保留其 inode 分配方式大致相同,直到持有该文件的打开句柄的所有进程都将其关闭。