Esta pergunta já tem uma resposta aqui:
Não consigo entender o comportamento ls
e cd
no seguinte caso:
Crie o diretório a/b/c
$ mkdir a/b/c -p
$ ls -lhRai
.:
total 324K
24512531 drwxrwxr-x 3 mayank mayank 312K May 22 16:23 .
24380771 drwxr-xr-x 34 mayank mayank 4.0K May 22 15:14 ..
25690305 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 a
./a:
total 324K
25690305 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 .
24512531 drwxrwxr-x 3 mayank mayank 312K May 22 16:23 ..
25690306 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 b
./a/b:
total 12K
25690306 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 .
25690305 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 ..
25690307 drwxrwxr-x 2 mayank mayank 4.0K May 22 16:23 c
./a/b/c:
total 8.0K
25690307 drwxrwxr-x 2 mayank mayank 4.0K May 22 16:23 .
25690306 drwxrwxr-x 3 mayank mayank 4.0K May 22 16:23 ..
cd
no diretório mais interno c
$ cd a/b/c
de outro terminal, remova o diretório a
, ou seja,
$ rm -rf a
mas ls
ainda está recebendo inode info
$ pwd
/home/mayank/Tmp/a/b/c
$ ls -lai .
total 0
$ ls -laid .
25690307 drwxrwxr-x 0 mayank mayank 0 May 22 16:23 .
$ ls -laid
25690307 drwxrwxr-x 0 mayank mayank 0 May 22 16:23 .
$ ls -laid ../
25690306 drwxrwxr-x 0 mayank mayank 0 May 22 16:24 ../
$ ls -laid ../..
25690305 drwxrwxr-x 0 mayank mayank 0 May 22 16:24 ../..
$ ls -laid ../../..
24512531 drwxrwxr-x 2 mayank mayank 319488 May 22 16:24 ../../..
offcourse cwd
arquivo em /proc
do bash está apontando para o diretório excluído
$ ls -l /proc/$$/cwd
lrwxrwxrwx 1 mayank mayank 0 May 22 16:32 /proc/13125/cwd -> /home/mayank/Tmp/a/b/c (deleted)
Além disso, não é possível entender o cd
behavior
$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
$ ls -li
total 0
$ ls -lid
25690306 drwxrwxr-x 0 mayank mayank 0 May 22 16:24 .
$ pwd
/home/mayank/Tmp/a/b/c/..
$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
$ pwd
/home/mayank/Tmp/a/b/c/../..
$ ls -lhid
25690305 drwxrwxr-x 0 mayank mayank 0 May 22 16:24 .
$ cd ..
Tmp:$ ls -lhtrai
total 320K
24380771 drwxr-xr-x 34 mayank mayank 4.0K May 22 15:14 ..
24512531 drwxrwxr-x 2 mayank mayank 312K May 22 16:24 .
Tmp:$ cd -
bash: cd: /home/mayank/Tmp/a/b/c/../..: No such file or directory
cd
não conseguiu obter informações sobre o pai em c
b
, mas a