1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)chdir.2 8.2 (Berkeley) 12/11/93 29.\" 30.Dd March 30, 2020 31.Dt CHDIR 2 32.Os 33.Sh NAME 34.Nm chdir , 35.Nm fchdir 36.Nd change current working directory 37.Sh LIBRARY 38.Lb libc 39.Sh SYNOPSIS 40.In unistd.h 41.Ft int 42.Fn chdir "const char *path" 43.Ft int 44.Fn fchdir "int fd" 45.Sh DESCRIPTION 46The 47.Fa path 48argument points to the pathname of a directory. 49The 50.Fn chdir 51system call 52causes the named directory 53to become the current working directory, that is, 54the starting point for path searches of pathnames not beginning with 55a slash, 56.Ql / . 57.Pp 58The 59.Fn fchdir 60system call 61causes the directory referenced by 62.Fa fd 63to become the current working directory, 64the starting point for path searches of pathnames not beginning with 65a slash, 66.Ql / . 67.Pp 68In order for a directory to become the current directory, 69a process must have execute (search) access to the directory. 70.Sh RETURN VALUES 71.Rv -std 72.Sh ERRORS 73The 74.Fn chdir 75system call 76will fail and the current working directory will be unchanged if 77one or more of the following are true: 78.Bl -tag -width Er 79.It Bq Er ENOTDIR 80A component of the path prefix is not a directory. 81.It Bq Er ENAMETOOLONG 82A component of a pathname exceeded 255 characters, 83or an entire path name exceeded 1023 characters. 84.It Bq Er ENOENT 85The named directory does not exist. 86.It Bq Er ELOOP 87Too many symbolic links were encountered in translating the pathname. 88.It Bq Er EACCES 89Search permission is denied for any component of 90the path name. 91.It Bq Er EFAULT 92The 93.Fa path 94argument 95points outside the process's allocated address space. 96.It Bq Er EIO 97An I/O error occurred while reading from or writing to the file system. 98.It Bq Er EINTEGRITY 99Corrupted data was detected while reading from the file system. 100.El 101.Pp 102The 103.Fn fchdir 104system call 105will fail and the current working directory will be unchanged if 106one or more of the following are true: 107.Bl -tag -width Er 108.It Bq Er EACCES 109Search permission is denied for the directory referenced by the 110file descriptor. 111.It Bq Er ENOTDIR 112The file descriptor does not reference a directory. 113.It Bq Er EBADF 114The argument 115.Fa fd 116is not a valid file descriptor. 117.El 118.Sh SEE ALSO 119.Xr chroot 2 120.Sh STANDARDS 121The 122.Fn chdir 123system call is expected to conform to 124.St -p1003.1-90 . 125.Sh HISTORY 126The 127.Fn chdir 128system call appeared in 129.At v1 . 130The 131.Fn fchdir 132system call appeared in 133.Bx 4.2 . 134