cd

From NetBSD Wiki

Jump to: navigation, search

The cd(1) command is by technical necessity<ref>A subprocess can't influence the current working directory of its parent. It only works the other way around; children inherit the current working directory from their parent</ref> always actually a shell builtin.

The builtin (often available as a hardcoded alias as chdir) changes the current working directory of the shell to a new directory. An example is best:

$ pwd
/home/yoda
$ cd src
$ pwd
/home/yoda/src

This just switches to the directory called src underneath the directory that is currently the working directory, which as pwd shows, was /home/yoda.

$ pwd
/home/yoda/src
$ cd ..
$ pwd
/home/yoda

The .. directory is an actual entry in every directory (so nothing magical to cd) which points to the higher directory /home/yoda.

$ cd src/foo
$ pwd
/home/yoda/foo
$ cd /home
$ pwd
/home

The latter cd command switched to the so-called absolute directory /home. All previous command looked up the directory name starting from the current directory, but when you precede a directory by a slash it will start looking at the root directory, which is the highest directory in the hierarchy.

To visually present the contents of a directory, see the ls page.

See also

Retrieved from "http://wiki.netbsd.se/cd"
Personal tools