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?

1
  • 6
    nitpick: directories hold files (including programs), not commands. Commands are the strings that you give to shell, which in turn runs the appropriate programs or builtin functions.
    – mike3996
    Mar 23, 2016 at 14:13

2 Answers 2

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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .