1chdir(2)                      System Calls Manual                     chdir(2)
2
3
4

NAME

6       chdir, fchdir - change working directory
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>
13
14       int chdir(const char *path);
15       int fchdir(int fd);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       fchdir():
20           _XOPEN_SOURCE >= 500
21               || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
22               || /* glibc up to and including 2.19: */ _BSD_SOURCE
23

DESCRIPTION

25       chdir() changes the current working directory of the calling process to
26       the directory specified in path.
27
28       fchdir() is identical to chdir(); the only difference is that  the  di‐
29       rectory is given as an open file descriptor.
30

RETURN VALUE

32       On  success,  zero is returned.  On error, -1 is returned, and errno is
33       set to indicate the error.
34

ERRORS

36       Depending on the filesystem, other errors can be  returned.   The  more
37       general errors for chdir() are listed below:
38
39       EACCES Search  permission  is denied for one of the components of path.
40              (See also path_resolution(7).)
41
42       EFAULT path points outside your accessible address space.
43
44       EIO    An I/O error occurred.
45
46       ELOOP  Too many symbolic links were encountered in resolving path.
47
48       ENAMETOOLONG
49              path is too long.
50
51       ENOENT The directory specified in path does not exist.
52
53       ENOMEM Insufficient kernel memory was available.
54
55       ENOTDIR
56              A component of path is not a directory.
57
58       The general errors for fchdir() are listed below:
59
60       EACCES Search permission was denied on the directory open on fd.
61
62       EBADF  fd is not a valid file descriptor.
63
64       ENOTDIR
65              fd does not refer to a directory.
66

STANDARDS

68       POSIX.1-2008.
69

HISTORY

71       POSIX.1-2001, SVr4, 4.4BSD.
72

NOTES

74       The current working directory is the starting  point  for  interpreting
75       relative pathnames (those not starting with '/').
76
77       A child process created via fork(2) inherits its parent's current work‐
78       ing directory.  The current working directory is left unchanged by  ex‐
79       ecve(2).
80

SEE ALSO

82       chroot(2), getcwd(3), path_resolution(7)
83
84
85
86Linux man-pages 6.05              2023-03-30                          chdir(2)
Impressum