I suggested using which to confirm whether a command works only as a shell builtin or alias. cd is an example of a command that works as a shell builtin. It would be much harder to implement the same function as a binary...

So why does my Fedora system have a binary /usr/bin/cd? It doesn't implement the magic necessary to affect the shell (parent process) working directory, to match the behaviour of the cd builtin. My Debian 8 system doesn't have /usr/bin/cd.

$ command -v sudo
$ command -v cd
$ which sudo
$ which cd
$ rpm -q --whatprovides /usr/bin/cd
$ (. /etc/os-release && echo $PRETTY_NAME)
Fedora 25 (Workstation Edition)
$ pwd
$ cd /home && pwd
$ /usr/bin/cd /home/alan && pwd
$ cd --help
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]

The full list of binaries provided by the bash package is

$ rpm -q --dump bash|grep /usr/bin|cut -f 1 -d ' '|cut -f 4

alias bash bashbug bashbug-64 bg cd command fc fg getopts hash jobs read sh type ulimit umask unalias wait

  • Once upon a time, when I was a student, we were assigned a work to write a shell. At some point, I thought it was unneeded to implement a built-in cd command, since there was a cd executable somewhere… Then I understood how wrong I was. Anyway, there was also a cd executable in Solaris, and I still have no idea how it might be useful… – user2233709 Mar 27 '17 at 14:33
  • 1
    See also #820192. – Stephen Kitt Mar 27 '17 at 14:36
  • 1

Browse other questions tagged or ask your own question.