Which package is the command 'cd' in?

Find out what type a command is using the type command.

$ type cd
cd is a shell builtin
$ type ls
ls is aliased to `ls --color=auto'
$ type cat
cat is /bin/cat

You can see, cd is a shell builtin.

This means, it's a part of your shell which is by default Bash. That's of course also the software package it's contained in.

For installed commands that are not shell builtins but executable files, use dpkg -S to find out the package:

$ dpkg -S $(which cat)
coreutils: /bin/cat

To get help for built in commands, use the help command (which is also built in):

$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

[... output shortened ...]

cd is necessarily a shell built-in. If the shell spawned a child process that changed the working directory and then exited, the parent process (the shell itself) would not be affected.

As to the source code of cd, all it needs to do is call chdir(2), which changes the working directory of the process. See chdir at opengroup.org which states:

The chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current working directory; that is, the starting point for path searches for pathnames not beginning with '/'.


Here is a man page for cd but it not an official one since cd is part of the "Shell Builtin Commands". Just like some other commands ...

alias, bg, bind, break, builtin, command, compgen, complete, 
continue, declare, dirs, disown, echo, enable, eval, exec, exit, 
export, fc, fg, getopts, hash, help, history, jobs, kill, let, local, 
logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, 
shopt, source, suspend, test, times, trap, type, typeset, ulimit,
umask, unalias, unset, wait 

See the man page for bash. From the link cd states:

cd [-L|-P] [dir]

Change the current directory to dir. The variable HOME is the default dir. The variable CDPATH defines the search path for the directory containing dir. Alternative directory names in CDPATH are separated by a colon (:). A null directory name in CDPATH is the same as the current directory, i.e., ''.''. If dir begins with a slash (/), then CDPATH is not used. The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command); the -L option forces symbolic links to be followed. An argument of - is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if - is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard output. The return value is true if the directory was successfully changed; false otherwise.

Which package is the command 'cd' in?

That would be bash