6
  1. cd /proc/$$/root/bin
  2. cd /bin

After running ls command on both the directory, I found that content of both directories are same (which is nothing but list of commands).

Is there any specific reason for this having same command-list in both directory?

guntbert
  • 13,475
snoop
  • 4,110
  • 9
  • 41
  • 58

2 Answers2

20

/proc is a "virtual" filesystem exposing some kernel and process related details.

$$ is a shell variable giving the PID of the shell running it.

/proc/$$/root is a symbolic link to the root directory as seen by the current shell. This could change in case you are chrooting.

In short, the two look identical because they are the same directory. If you execute ls -ld /proc/$$/root you will see that it is a symbolic link to /, and therefore /proc/$$/root/bin and /bin are the same directory.

Law29
  • 135
EnzoR
  • 1,747
0

That's because they are, in fact, the same directories¹:

$ test /proc/$$/root/bin -ef /bin; echo $?
0

(The -ef test checks whether two paths refer to the same file object.)

The same holds true for /proc/$$/root and /, because

$ readlink /proc/$$/root
/

¹ unless you are in a chroot environment which may point /proc/$$/root to a different directory.

David Foerster
  • 36,890
  • 56
  • 97
  • 151