0

On OS X 10.8 I was looking at my /bin folder and found that cd was not there, but rather in the /usr/bin folder. Why is that? From the FHS (Filesystem Hierarchy Standard. I know that /bin should contain essential binaries, i.e. those required when no other filesystems are mounted. Is cd not essential enough? (by the way, it appears the "su" command is also in /usr/bin). Now, I know that OS X doesn't follow strictly the FHS, but is there a reason for these different location of binaries?

  • 1
    When using acronyms, that may be uncommon to most e.g. FHS (Filesystem Hierarchy Standard), consider describing or linking so as those that do not know them off the top of their head aren't totally lost. – user3439894 Jun 25 '15 at 17:47
  • As FHS is Linux why should or does it apply to Unix ? – user151019 Jun 25 '15 at 18:04
  • @user3439894 sorry, you are totally right. I edited the question. – ggrim Jun 25 '15 at 19:25
  • @Mark I thought FHS it's more Unix than just Linux – ggrim Jun 25 '15 at 19:32
  • Wikipedia says "It is maintained by the Linux Foundation. The latest version is 3.0, released on 3 June 2015. [1] Currently it is only used by Linux distributions." – user151019 Jun 25 '15 at 20:47
3

cd is a shell builtin, and has to be a builtin to work. If it were executed as a normal command, it'd run as a subprocess, change that subprocess's directory, and then exit... having no effect at all on the parent shell's directory.

As for su: the fondamental distinction between /bin and /usr/bin is that /usr/bin might be on a different filesystem from the root, and hence not be available early in the boot process; thus /bin (and /sbin) must contain all of the commands needed early in the boot process. On OS X, su apparently isn't needed during boot.

  • Thanks for your helpful reply! Out of curiosity... cd being a shell builtin means that it's code is stored inside /bin/bash executable? (sorry, I do understand the meaning of your answer, I just don't know how a shell builtin it's implemented) – ggrim Jun 25 '15 at 19:44
  • 1
    @ggrim: I wouldn't say "stored inside" so much as "is part of". I believe it's actually implemented as a function included in the bash source code. BTW, it's not just bash -- every shell shell (zsh, dash, etc) has to have cd as a builtin, or it'd fail for the reason I gave. You might be interested in this previous question on the Unix&Linux SE. – Gordon Davisson Jun 25 '15 at 20:15
  • Also, this answer has an interesting historical note about cd as a builtin vs. separate program. – Gordon Davisson Jun 25 '15 at 20:18

You must log in to answer this question.

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