1cd(1)                            User Commands                           cd(1)
2
3
4

NAME

6       cd, chdir, pushd, popd, dirs - change working directory
7

SYNOPSIS

9       /usr/bin/cd [directory]
10
11
12   sh
13       cd [argument]
14
15
16       chdir [argument]
17
18
19   csh
20       cd [dir]
21
22
23       chdir [dir]
24
25
26       pushd [+n | dir]
27
28
29       popd [+n]
30
31
32       dirs [-l]
33
34
35   ksh, ksh93
36       cd [-L] [-P] [arg]
37
38
39       cd old new
40
41

DESCRIPTION

43   /usr/bin/cd
44       The /usr/bin/cd utility changes the current directory in the context of
45       the cd utility only. This is in contrast to the version built into  the
46       shell.  /usr/bin/cd  has  no  effect on the invoking process but can be
47       used to determine whether or not a given directory can be  set  as  the
48       current directory.
49
50   sh
51       The Bourne shell built-in cd changes the current directory to argument.
52       The shell parameter HOME is the default argument. The  shell  parameter
53       CDPATH  defines  the search path for the directory containing argument.
54       Alternative directory names are separated by a colon (:).  The  default
55       path  is  <null> (specifying the current directory). The current direc‐
56       tory is specified by a null path name,  which  can  appear  immediately
57       after  the  equal sign or between the colon delimiters anywhere else in
58       the path list. If argument begins with `/', `.', or  `..',  the  search
59       path is not used. Otherwise, each directory in the path is searched for
60       argument. cd must have execute (search) permission in argument. Because
61       a  new process is created to execute each command, cd would be ineffec‐
62       tive if it were written as a normal command; therefore,  it  is  recog‐
63       nized  by  and  is  internal  to  the  shell.  (See  pwd(1), sh(1), and
64       chdir(2)).
65
66
67       chdir is just another way to call cd.
68
69   csh
70       If dir is not specified, the C shell built-in  cd  uses  the  value  of
71       shell  parameter  HOME as the new working directory. If dir specifies a
72       complete path starting with `/', `.', or  `..',  dir  becomes  the  new
73       working directory. If neither case applies, cd tries to find the desig‐
74       nated directory relative to one of the paths specified  by  the  CDPATH
75       shell  variable.  CDPATH  has the same syntax as, and similar semantics
76       to, the PATH shell variable. cd must have execute  (search)  permission
77       in  dir.  Because  a new process is created to execute each command, cd
78       would be ineffective if it were written as a normal command; therefore,
79       it is recognized by and is internal to the C-shell. (See pwd(1), sh(1),
80       and chdir(2)).
81
82
83       chdir changes the shell's working directory to  directory  dir.  If  no
84       argument  is given, change to the home directory of the user. If dir is
85       a relative pathname not found in the current directory, check for it in
86       those  directories listed in the cdpath variable. If dir is the name of
87       a shell variable whose value starts with a /, change to  the  directory
88       named by that value.
89
90
91       pushd  pushes  a directory onto the directory stack. With no arguments,
92       exchange the top two elements.
93
94       +n     Rotate the n'th entry to the top of the stack and cd to it.
95
96
97       dir    Push the current working directory onto the stack and change  to
98              dir.
99
100
101
102       popd pops the directory stack and cd to the new top directory. The ele‐
103       ments of the directory stack are numbered from 0 starting at the top.
104
105       +n    Discard the n'th entry in the stack.
106
107
108
109       dirs prints the directory stack, most recent to  the  left;  the  first
110       directory shown is the current directory. With the -l argument, produce
111       an unabbreviated printout; use of the ~ notation is suppressed.
112
113   ksh, ksh93
114       The Korn shell built-in cd command can be in either of  two  forms.  In
115       the first form it changes the current directory to arg. If arg is the
116       directory is changed to the previous directory. The shell variable HOME
117       is  the default arg. The environment variable PWD is set to the current
118       directory. If the PWD is changed, the OLDPWD environment variable shall
119       also be changed to the value of the old working directory, that is, the
120       current working directory immediately  prior  to  the  call  to  change
121       directory  (cd).  The shell variable CDPATH defines the search path for
122       the directory containing arg. Alternative directory names are separated
123       by a colon (:). The default path is null (specifying the current direc‐
124       tory). The current directory is specified by a null  path  name,  which
125       can appear immediately after the equal sign or between the colon delim‐
126       iters anywhere else in the path list. If arg begins with a `/', `.', or
127       `..',  then  the  search path is not used. Otherwise, each directory in
128       the path is searched for arg. If unsuccessful, cd  attempts  to  change
129       directories to the pathname formed by the concatenation of the value of
130       PWD, a slash character, and arg.
131
132       -L    Handles the operation dot-dot (..) logically. Symbolic link  com‐
133             ponents are not resolved before dot-dot components are processed.
134
135
136       -P    Handles  the operand dot-dot physically. Symbolic link components
137             are resolved before dot-dot components are processed.
138
139
140
141       If both -L and -P options are specified, the last option to be  invoked
142       is  used  and  the other is ignored. If neither -L nor -P is specified,
143       the operand is handled dot-dot logically.
144
145
146       The second form of cd substitutes the string new for the string old  in
147       the  current directory name, PWD and tries to change to this new direc‐
148       tory.
149
150
151       The cd command cannot be executed by rksh. Because  a  new  process  is
152       created  to  execute  each  command, cd would be ineffective if it were
153       written as a normal command; therefore, it  is  recognized  by  and  is
154       internal to the Korn shell. (See pwd(1), sh(1), and chdir(2)).
155

OPERANDS

157       The following operands are supported:
158
159       directory    An  absolute  or  relative  pathname of the directory that
160                    becomes the new working directory. The interpretation of a
161                    relative  pathname by cd depends on the CDPATH environment
162                    variable.
163
164

OUTPUT

166       If a non-empty directory name from CDPATH is used, an absolute pathname
167       of  the new working directory is written to the standard output as fol‐
168       lows:
169
170
171       "%s\n", <new directory>
172
173
174       Otherwise, there is no output.
175

ENVIRONMENT VARIABLES

177       See environ(5) for descriptions of the following environment  variables
178       that  affect  the execution of cd: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
179       and NLSPATH.
180
181       CDPATH    A colon-separated list of pathnames that  refer  to  directo‐
182                 ries.  If the directory operand does not begin with a slash (
183                 / ) character, and the first component is not dot or dot-dot,
184                 cd searches for directory relative to each directory named in
185                 the CDPATH variable, in the order  listed.  The  new  working
186                 directory  sets  to  the  first  matching directory found. An
187                 empty string in place of a directory pathname represents  the
188                 current  directory. If CDPATH is not set, it is treated as if
189                 it were an empty string.
190
191
192       HOME      The name of the home directory, used when no directory  oper‐
193                 and is specified.
194
195
196       OLDPWD    A pathname of the previous working directory, used by cd-.
197
198
199       PWD       A  pathname of the current working directory, set by cd after
200                 it has changed to that directory.
201
202

EXIT STATUS

204       The following exit values are returned by cd:
205
206       0     The directory was successfully changed.
207
208
209       >0    An error occurred.
210
211

ATTRIBUTES

213       See attributes(5) for descriptions of the following attributes:
214
215   csh, ksh, sh
216       ┌─────────────────────────────┬─────────────────────────────┐
217       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
218       ├─────────────────────────────┼─────────────────────────────┤
219       │Availability                 │SUNWcsu                      │
220       ├─────────────────────────────┼─────────────────────────────┤
221       │Interface Stability          │Committed                    │
222       ├─────────────────────────────┼─────────────────────────────┤
223       │Standard                     │See standards(5).            │
224       └─────────────────────────────┴─────────────────────────────┘
225
226   ksh93
227       ┌─────────────────────────────┬─────────────────────────────┐
228       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
229       ├─────────────────────────────┼─────────────────────────────┤
230       │Availability                 │SUNWcsu                      │
231       ├─────────────────────────────┼─────────────────────────────┤
232       │Interface Stability          │Uncommitted                  │
233       └─────────────────────────────┴─────────────────────────────┘
234

SEE ALSO

236       csh(1), ksh(1), ksh93(1), pwd(1), sh(1), chdir(2), attributes(5), envi‐
237       ron(5), standards(5)
238
239
240
241SunOS 5.11                        8 Apr 2008                             cd(1)
Impressum