| 1 |
.\" Copyright 1992, Drew Eckhardt <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH chdir 2 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
chdir, fchdir \- change working directory |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <unistd.h> |
| 15 |
.P |
| 16 |
.BI "int chdir(const char *" path ); |
| 17 |
.BI "int fchdir(int " fd ); |
| 18 |
.fi |
| 19 |
.P |
| 20 |
.RS -4 |
| 21 |
Feature Test Macro Requirements for glibc (see |
| 22 |
.BR feature_test_macros (7)): |
| 23 |
.RE |
| 24 |
.P |
| 25 |
.BR fchdir (): |
| 26 |
.nf |
| 27 |
_XOPEN_SOURCE >= 500 |
| 28 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 29 |
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L |
| 30 |
|| /* glibc up to and including 2.19: */ _BSD_SOURCE |
| 31 |
.fi |
| 32 |
.SH DESCRIPTION |
| 33 |
.BR chdir () |
| 34 |
changes the current working directory of the calling process to the |
| 35 |
directory specified in |
| 36 |
.IR path . |
| 37 |
.P |
| 38 |
.BR fchdir () |
| 39 |
is identical to |
| 40 |
.BR chdir (); |
| 41 |
the only difference is that the directory is given as an |
| 42 |
open file descriptor. |
| 43 |
.SH RETURN VALUE |
| 44 |
On success, zero is returned. |
| 45 |
On error, \-1 is returned, and |
| 46 |
.I errno |
| 47 |
is set to indicate the error. |
| 48 |
.SH ERRORS |
| 49 |
Depending on the filesystem, other errors can be returned. |
| 50 |
The more |
| 51 |
general errors for |
| 52 |
.BR chdir () |
| 53 |
are listed below: |
| 54 |
.TP |
| 55 |
.B EACCES |
| 56 |
Search permission is denied for one of the components of |
| 57 |
.IR path . |
| 58 |
(See also |
| 59 |
.BR path_resolution (7).) |
| 60 |
.TP |
| 61 |
.B EFAULT |
| 62 |
.I path |
| 63 |
points outside your accessible address space. |
| 64 |
.TP |
| 65 |
.B EIO |
| 66 |
An I/O error occurred. |
| 67 |
.TP |
| 68 |
.B ELOOP |
| 69 |
Too many symbolic links were encountered in resolving |
| 70 |
.IR path . |
| 71 |
.TP |
| 72 |
.B ENAMETOOLONG |
| 73 |
.I path |
| 74 |
is too long. |
| 75 |
.TP |
| 76 |
.B ENOENT |
| 77 |
The directory specified in |
| 78 |
.I path |
| 79 |
does not exist. |
| 80 |
.TP |
| 81 |
.B ENOMEM |
| 82 |
Insufficient kernel memory was available. |
| 83 |
.TP |
| 84 |
.B ENOTDIR |
| 85 |
A component of |
| 86 |
.I path |
| 87 |
is not a directory. |
| 88 |
.P |
| 89 |
The general errors for |
| 90 |
.BR fchdir () |
| 91 |
are listed below: |
| 92 |
.TP |
| 93 |
.B EACCES |
| 94 |
Search permission was denied on the directory open on |
| 95 |
.IR fd . |
| 96 |
.TP |
| 97 |
.B EBADF |
| 98 |
.I fd |
| 99 |
is not a valid file descriptor. |
| 100 |
.TP |
| 101 |
.B ENOTDIR |
| 102 |
.I fd |
| 103 |
does not refer to a directory. |
| 104 |
.SH STANDARDS |
| 105 |
POSIX.1-2024. |
| 106 |
.SH HISTORY |
| 107 |
.TP |
| 108 |
.BR chdir () |
| 109 |
SVr4, |
| 110 |
POSIX.1-1988, |
| 111 |
4.4BSD. |
| 112 |
.TP |
| 113 |
.BR fchdir () |
| 114 |
SVr4, |
| 115 |
4.4BSD, |
| 116 |
SUSv1, |
| 117 |
POSIX.1-2001 XSI, |
| 118 |
POSIX.1-2008. |
| 119 |
.SH NOTES |
| 120 |
The current working directory is the starting point for interpreting |
| 121 |
relative pathnames (those not starting with \[aq]/\[aq]). |
| 122 |
.P |
| 123 |
A child process created via |
| 124 |
.BR fork (2) |
| 125 |
inherits its parent's current working directory. |
| 126 |
The current working directory is left unchanged by |
| 127 |
.BR execve (2). |
| 128 |
.SH SEE ALSO |
| 129 |
.BR chroot (2), |
| 130 |
.BR getcwd (3), |
| 131 |
.BR path_resolution (7) |