Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  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?

share|improve this question
5  
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. – progo Mar 23 at 14:13
up vote 20 down vote accepted

/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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.