CHDIR(3P)
π CHDIR(3P) β bestie we're MOVING π
okay so real talk, this page lives in the POSIX Programmer's Manual, and it's giving β¨ official standards energy β¨. Just a heads up before we dive in: the Linux implementation of this interface may differ, so if you're on Linux you lowkey need to go check the corresponding Linux manual page for the deets on Linux behavior. Also possible: the interface just isn't implemented on Linux at all. π Not me warning you first, that's just being a good friend.
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
π NAME π
chdir β change working directory. That's it, that's the whole vibe. You're packing up and moving somewhere new. π§³
β¨ SYNOPSIS β¨
#include <unistd.h>
int chdir(const char *path);
π¦ DESCRIPTION π¦
The chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current working directory. Like, that's your new home base, bestie. π
And what does "current working directory" even mean, you ask? It's the starting point for path searches for pathnames that don't begin with '/'. So if you type a relative path, the search literally starts from wherever you just chdir()'d into. main character location energy fr fr. π
π RETURN VALUE π
- Slay: on successful completion,
0shall be returned. β¨ - Not slay: otherwise,
-1shall be returned, and the current working directory shall remain unchanged (so you're not left homeless, okurrr), anderrnoshall be set to indicate the error.
π ERRORS π
The chdir() function shall fail if:
EACCESβ Search permission is denied for any component of the pathname. π«ELOOPβ A loop exists in symbolic links encountered during resolution of thepathargument. π (a symlink ouroboros, literally)ENAMETOOLONGβ The length of a component of a pathname is longer than{NAME_MAX}. πENOENTβ A component ofpathdoes not name an existing directory, orpathis an empty string. π»ENOTDIRβ A component of the pathname names an existing file that is neither a directory nor a symbolic link to a directory. like bestie that's a file, not a folder, read the room. π
The chdir() function may fail if:
ELOOPβ More than{SYMLOOP_MAX}symbolic links were encountered during resolution of thepathargument. ππENAMETOOLONGβ The length of a pathname exceeds{PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds{PATH_MAX}. π΅
Heads up: the following sections are informative. They're the β¨loreβ¨ not the law.
π EXAMPLES π
π Changing the Current Working Directory π
The following example makes the value pointed to by directory, /tmp, the current working directory. No cap.
#include <unistd.h>
...
char *directory = "/tmp";
int ret;
ret = chdir (directory);
π«Ά APPLICATION USAGE π«Ά
None.
π§ RATIONALE π§
The chdir() function only affects the working directory of the current process. That's it. Just you. Not your friends, not the shell next door, not the whole system. individual queen behavior. π
β FUTURE DIRECTIONS β
None.
π₯ SEE ALSO π₯
getcwd()- The Base Definitions volume of POSIX.1β2017,
<unistd.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document (so if there's beef, the original wins, periodt). The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html.
okay that's the whole page bestie, ily, go change some directories responsibly πβ¨
IEEE/The Open Group, 2017 β yeah that's the source and the date, mwah, sign-off complete, π bye π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms