Glossary

cd

cd ("change directory") moves the shell's current working directory to the path you give it. It is a shell builtin, not a separate program, because changing the directory of an external program would only affect that child process, not the shell itself.

cd /etc                  # absolute path
cd projects/tblinux      # relative to $PWD
cd ..                    # parent directory
cd -                     # previous directory (toggle)
cd                       # home directory ($HOME)
cd ~alice                # alice's home directory

The shell maintains a directory stack (pushd/popd/dirs) for more elaborate navigation, and $OLDPWD` always holds the last directory you were in. In scripts, prefer `cd "$dir" || exit so a missing target aborts rather than silently continuing in the wrong place.

Related terms: pwd, ls, Shell

Discussed in:

Textbook of Linux — Learn Linux on iPhone — Download on the App Store