0

I am trying to find the path of basic commands like ls or cd using which command. I see the path for ls but not for cd. Of course both the commands work fine. Any idea?

$ which ls
/bin/ls
$ which cd
$
Vee
  • 1

1 Answers1

2

cd is always built-in command provided by the shell itself. It will not be found as an external utility. This is in no way specific to Linux.

From the "APPLICATION USAGE" section for cd in the POSIX standard:

Since cd affects the current shell execution environment, it is always provided as a shell regular built-in. If it is called in a subshell or separate utility execution environment, such as one of the following:

(cd /tmp)
nohup cd
find . -exec cd {} \;

it does not affect the working directory of the caller's environment.


A portable way of finding the path of a command is to use command -v:

bash-4.4$ command -v ls
/bin/ls
bash-4.4$ command -v cd
cd

type will be slightly more verbose:

bash-4.4$ type ls
ls is /bin/ls
bash-4.4$ type cd
cd is a shell builtin

See also "Why not use "which"? What to use then?"

Kusalananda
  • 333,661