CHDIR(3POSIX)
π CHDIR(3POSIX) π
okay bestie, we're doing the POSIX Programmer's Manual today. This page lives in the POSIX Programmer's Manual, which is a whole vibe of its own β and heads up, the Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π
β¨ 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 on Linux behavior β or the interface may not be implemented on Linux. No cap.
πΈ NAME πΈ
chdir β change working directory. That's it. That's the whole job. π
π SYNOPSIS π
#include <unistd.h>
int chdir(const char *path);
π¦ DESCRIPTION π¦
So basically, the chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current working directory. Which is a fancy way of saying: it becomes the starting point for path searches for pathnames that don't begin with '/'. Like, if you're lost and you need a home base? This is how you get one. π β¨
β RETURN VALUE β
Upon successful completion, 0 shall be returned. Slay.
Otherwise, -1 shall be returned, the current working directory shall remain unchanged (it's not moving, bestie), and errno shall be set to indicate the error.
π ERRORS π
The chdir() function shall fail if:
EACCESβ search permission is denied for any component of the pathname. Rude, honestly.ELOOPβ a loop exists in symbolic links encountered during resolution of thepathargument. π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. Nothing there, babes. π«₯ENOTDIRβ a component of the pathname names an existing file that is neither a directory nor a symbolic link to a directory.
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}.
The following sections are informative. (i.e. 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. Iconic behavior, truly.
#include <unistd.h>
...
char *directory = "/tmp";
int ret;
ret = chdir (directory);
π APPLICATION USAGE π
None. Literally nothing. We're chill like that. βοΈ
π§ RATIONALE π§
The chdir() function only affects the working directory of the current process. So don't be out here thinking you're changing everyone's directory β you're not. It's giving "personal bubble". π«§
π₯ FUTURE DIRECTIONS π₯
None. The future is a blank canvas and chdir is not on it. π¨
π 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. 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 β massive thanks to IEEE/The Open Group, dated 2017, who brought us CHDIR(3POSIX) in the first place. mwah. π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms