2

This question already has an answer here:

I am not able to understand ls and cd behaviour in following case : Create directory 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 to innermost directory c

$ cd a/b/c

from another terminal, remove directory a, i.e.

$ rm -rf a

but ls is still getting 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 file in /proc of bash is pointing to deleted dir

$ ls -l /proc/$$/cwd
lrwxrwxrwx 1 mayank mayank 0 May 22 16:32 /proc/13125/cwd -> /home/mayank/Tmp/a/b/c (deleted)

Also, not able to understand cd behaviour

$ 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 was not able to get parent dir info in c b , but a

marked as duplicate by Stephen Kitt linux May 22 '18 at 11:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.