1 CD(1)                            User Commands                           CD(1)
   2 
   3 
   4 
   5 NAME
   6        cd, chdir, pushd, popd, dirs - change working directory
   7 
   8 SYNOPSIS
   9        /usr/bin/cd [directory]
  10 
  11 
  12    csh
  13        cd [dir]
  14 
  15 
  16        chdir [dir]
  17 
  18 
  19        pushd [+n | dir]
  20 
  21 
  22        popd [+n]
  23 
  24 
  25        dirs [-l]
  26 
  27 
  28    ksh93
  29        cd [-L] [-P] [arg]
  30 
  31 
  32        cd old new
  33 
  34 
  35 DESCRIPTION
  36    /usr/bin/cd
  37        The /usr/bin/cd utility changes the current directory in the context of
  38        the cd utility only. This is in contrast to the version built into the
  39        shell. /usr/bin/cd has no effect on the invoking process but can be
  40        used to determine whether or not a given directory can be set as the
  41        current directory.
  42 
  43    csh
  44        If dir is not specified, the C shell built-in cd uses the value of
  45        shell parameter HOME as the new working directory. If dir specifies a
  46        complete path starting with `/', `.', or `..', dir becomes the new
  47        working directory. If neither case applies, cd tries to find the
  48        designated directory relative to one of the paths specified by the
  49        CDPATH shell variable. CDPATH has the same syntax as, and similar
  50        semantics to, the PATH shell variable. cd must have execute (search)
  51        permission in dir. Because a new process is created to execute each
  52        command, cd would be ineffective if it were written as a normal
  53        command; therefore, it is recognized by and is internal to the C-shell.
  54        (See pwd(1), sh(1), and chdir(2)).
  55 
  56 
  57        chdir changes the shell's working directory to directory dir. If no
  58        argument is given, change to the home directory of the user. If dir is
  59        a relative pathname not found in the current directory, check for it in
  60        those directories listed in the cdpath variable. If dir is the name of
  61        a shell variable whose value starts with a /, change to the directory
  62        named by that value.
  63 
  64 
  65        pushd pushes a directory onto the directory stack. With no arguments,
  66        exchange the top two elements.
  67 
  68        +n
  69               Rotate the n'th entry to the top of the stack and cd to it.
  70 
  71 
  72        dir
  73               Push the current working directory onto the stack and change to
  74               dir.
  75 
  76 
  77 
  78        popd pops the directory stack and cd to the new top directory. The
  79        elements of the directory stack are numbered from 0 starting at the
  80        top.
  81 
  82        +n
  83              Discard the n'th entry in the stack.
  84 
  85 
  86 
  87        dirs prints the directory stack, most recent to the left; the first
  88        directory shown is the current directory. With the -l argument, produce
  89        an unabbreviated printout; use of the ~ notation is suppressed.
  90 
  91    ksh93
  92        The Korn shell built-in cd command can be in either of two forms. In
  93        the first form it changes the current directory to arg. If arg is - the
  94        directory is changed to the previous directory. The shell variable HOME
  95        is the default arg. The environment variable PWD is set to the current
  96        directory. If the PWD is changed, the OLDPWD environment variable shall
  97        also be changed to the value of the old working directory, that is, the
  98        current working directory immediately prior to the call to change
  99        directory (cd). The shell variable CDPATH defines the search path for
 100        the directory containing arg. Alternative directory names are separated
 101        by a colon (:). The default path is null (specifying the current
 102        directory). The current directory is specified by a null path name,
 103        which can appear immediately after the equal sign or between the colon
 104        delimiters anywhere else in the path list. If arg begins with a `/',
 105        `.', or `..', then the search path is not used. Otherwise, each
 106        directory in the path is searched for arg. If unsuccessful, cd attempts
 107        to change directories to the pathname formed by the concatenation of
 108        the value of PWD, a slash character, and arg.
 109 
 110        -L
 111              Handles the operation dot-dot (..) logically. Symbolic link
 112              components are not resolved before dot-dot components are
 113              processed.
 114 
 115 
 116        -P
 117              Handles the operand dot-dot physically. Symbolic link components
 118              are resolved before dot-dot components are processed.
 119 
 120 
 121 
 122        If both -L and -P options are specified, the last option to be invoked
 123        is used and the other is ignored. If neither -L nor -P is specified,
 124        the operand is handled dot-dot logically.
 125 
 126 
 127        The second form of cd substitutes the string new for the string old in
 128        the current directory name, PWD and tries to change to this new
 129        directory.
 130 
 131 
 132        The cd command cannot be executed by rksh. Because a new process is
 133        created to execute each command, cd would be ineffective if it were
 134        written as a normal command; therefore, it is recognized by and is
 135        internal to the Korn shell. (See pwd(1), ksh93(1), and chdir(2)).
 136 
 137 OPERANDS
 138        The following operands are supported:
 139 
 140        directory
 141                     An absolute or relative pathname of the directory that
 142                     becomes the new working directory. The interpretation of a
 143                     relative pathname by cd depends on the CDPATH environment
 144                     variable.
 145 
 146 
 147 OUTPUT
 148        If a non-empty directory name from CDPATH is used, an absolute pathname
 149        of the new working directory is written to the standard output as
 150        follows:
 151 
 152 
 153        "%s\n", <new directory>
 154 
 155 
 156        Otherwise, there is no output.
 157 
 158 ENVIRONMENT VARIABLES
 159        See environ(5) for descriptions of the following environment variables
 160        that affect the execution of cd: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
 161        and NLSPATH.
 162 
 163        CDPATH
 164                  A colon-separated list of pathnames that refer to
 165                  directories. If the directory operand does not begin with a
 166                  slash ( / ) character, and the first component is not dot or
 167                  dot-dot, cd searches for directory relative to each directory
 168                  named in the CDPATH variable, in the order listed. The new
 169                  working directory sets to the first matching directory found.
 170                  An empty string in place of a directory pathname represents
 171                  the current directory. If CDPATH is not set, it is treated as
 172                  if it were an empty string.
 173 
 174 
 175        HOME
 176                  The name of the home directory, used when no directory
 177                  operand is specified.
 178 
 179 
 180        OLDPWD
 181                  A pathname of the previous working directory, used by cd-.
 182 
 183 
 184        PWD
 185                  A pathname of the current working directory, set by cd after
 186                  it has changed to that directory.
 187 
 188 
 189 EXIT STATUS
 190        The following exit values are returned by cd:
 191 
 192        0
 193              The directory was successfully changed.
 194 
 195 
 196        >0
 197              An error occurred.
 198 
 199 
 200 ATTRIBUTES
 201        See attributes(5) for descriptions of the following attributes:
 202 
 203    csh
 204 
 205        +--------------------+-------------------+
 206        |  ATTRIBUTE TYPE    |  ATTRIBUTE VALUE  |
 207        +--------------------+-------------------+
 208        |Interface Stability | Committed         |
 209        +--------------------+-------------------+
 210        |Standard            | See standards(5). |
 211        +--------------------+-------------------+
 212 
 213    ksh93
 214 
 215        +--------------------+-----------------+
 216        |  ATTRIBUTE TYPE    | ATTRIBUTE VALUE |
 217        +--------------------+-----------------+
 218        |Interface Stability | Uncommitted     |
 219        +--------------------+-----------------+
 220 
 221 SEE ALSO
 222        csh(1), ksh93(1), pwd(1), chdir(2), attributes(5), environ(5),
 223        standards(5)
 224 
 225 
 226 
 227                                February 9, 2021                          CD(1)