On Unix-like operating systems, chdir is the system call for changing the current working directory.
This page covers the GNU/Linux version of chdir.
Description
chdir changes the current working directory of the calling process to the directory specified in path.
- Description
- Syntax
- Return value
- Errors
- Notes
- Related commands
- Linux commands help
Syntax
#include <unistd.h> int chdir(const char *path);
Return value
On success, zero (0) is returned. On an error, -1 is returned, and errno is set appropriately.
Errors
Depending on the filesystem, other errors can be returned. The more general errors for chdir are listed below:
Notes
The current working directory is the starting point for interpreting relative pathnames (those not starting with ‘/’).
A child process created via fork inherits its parent’s current working directory. The current working directory is left unchanged by execve.
Related commands
cd — Change the working directory.chroot — Run a command or shell from another directory, and treat that directory as root.ls — List the contents of a directory or directories.