[Previous] [Contents] [Next]


Change working directory (POSIX)


cd [directory]


The pathname of the directory that will become the new working directory. The interpretation of a relative pathname by cd depends on the CDPATH environment variable (see below).


The cd command is a shell built-in that changes the current or working directory of the shell to the directory named as its argument. All filenames that don't start with a slash (/) are assumed to be relative to your current working directory.

The command:


with no arguments changes the current working directory to the directory named by your HOME environment variable set when you logged in. This is equivalent to:

cd $HOME

if the HOME environment variable is set.

If the HOME environment variable isn't defined, or has the null string as its value, then the current working directory is changed to the first non-NULL directory named in your CDPATH environment variable. If CDPATH is not set, the current working directory will not be changed.

The cd command makes use of CDPATH, which is analogous to the use of the PATH variable in the shell. It lets you name a directory with a one-component name rather than a full pathname.

CDPATH is a list of pathnames, separated by colons. If the directory specified in the cd command doesn't begin with a slash (/), and the first component isn't dot (.) or dot dot (..), cd searches for directory relative to each path named in the CDPATH variable, in the order listed. The new working directory is set to the first matching path found. An empty string in place of a directory pathname represents the current directory. If CDPATH isn't set, it is treated as if it were an empty string.

For example, if CDPATH is set to /home/fred/:, the command:

cd newdir

looks for the /home/fred/newdir and then for the ./newdir directories and makes the first one of those it finds the working directory.


Some shells, including the standard QNX shell (sh), have extensions involving two argument invocations and use of - (dash) as an argument. See sh for details.

Symbolic links

In some UNIX systems, cd modifies the pathname given to it if that pathname contains symbolic links. As a result, the pathname of the new current working directory may differ from the one given to cd. In QNX, however, cd doesn't modify the pathname-aside from collapsing ".." references. For example:

    cd /home/luc/test/../doc

would result in a current working directory of /home/luc/doc, even if some of the elements in the pathname were symbolic links.

For more information about symbolic links and ".." references, see System Architecture.


Change directory to the directory named by the HOME environment variable:


Change to the next highest directory in the directory structure:

cd ..

Change directory to the root directory:

cd /

Change to the /path/dir directory:

cd /path/dir

Change to the directory /src, resolved via the pathname space of node 61:

cd //61/src

Change to the directory two levels above the current working directory:

cd ../..

Change to the directory two levels above the current working directory, then to the files directory below in the directory tree:

cd ../../files


You can use the pwd command to display the current working directory.

Environment variables:

When defined, CDPATH lists pathname components that are applied to any specified directory that doesn't begin with a slash (/), dot (.) or dot-dot (..).
The name of the home directory, used when no directory operand is specified.

Exit status:

The directory was successfully changed.
An error occurred; the directory remains unchanged.


The cd utility is available only as a shell builtin.

See also:

sh, pwd

System Architecture

[Previous] [Contents] [Next]