tags:

views:

43

answers:

6

I read that the executables for the commands issued using exec() calls are supposed to be stored in directories that are part of the PATH variable.

Accordingly, I found the executables for ls, chmod, grep, cat in /bin.

However, I could not find the executable for cd.

Where is it located?

+1  A: 

According to this, cd is always a built-in command and never an executable:

Since cd affects the current shell execution environment, it is always provided as a shell regular built-in.

Pekka
+1  A: 

cd is part of the shell; an internal command. There is no binary for it.

Delan Azabani
+1  A: 

The command cd is built-in in your command line shell. It could not affect the working directory of your shell otherwise.

Peter G.
+2  A: 

cd is a shell built-in, unfortunately.

$ type cd
cd is a shell builtin

...from http://www.linuxquestions.org/questions/linux-newbie-8/whereis-cd-sudo-doesnt-find-cd-464767/

But you should be able to get it working with:

sh -c "cd /somedir; do something"
harvest316
the type command was really useful in understanding this concept. Thanks!
Kedar Soparkar
+2  A: 

A process can only affect its own working directory. When an executable is executed by the shell it executes as a child process, so a cd executable (if one existed) would change that child process's working directory without affecting the parent process (the shell), hence the cd command must be implemented as a shell built-in that actually executes in the shell's own process.

Laurence Gonsalves
+1 for in-depth explanation
Pekka
+1  A: 
Jörg W Mittag