Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

chdir - change working directory

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

int chdir(const char *path);

Description

chdir() causes the directory pointed to by the path argument to become the currentworking directory, i.e. the starting point for path searches for pathnames not beginning
with a /.

path points to the pathname of a directory.

Return val.

0

-1

if successful. The specified directory becomes the current working directory.

if an error occurs. errno is set to indicate the error.

Errors

chdir() will fail if:

EACCES

Search permission is denied for any component of the pathname.

Extension

EFAULT

EINTR

EIO

ELOOP

path is an invalid address.

A signal was caught during the execution of the chdir() system call.

An I/O error occurred while reading from or writing to the file system.

Too many symbolic links were encountered in resolving path. (End)

ENAMETOOLONG 



The length of path exceeds {PATH_MAX} or a component of path is longer than {NAME_MAX} and {POSIX_NO_TRUNC} is set.



ENOENT

ENOTDIR

A component of path does not exist or is a null pathname.

A component of the pathname is not a directory.

Notes

The effect of changing the working directory applies only for the duration of the current program (or current shell). If a new program or shell is started, the home directory is reset as the current working directory.

In order to make a directory the current working directory, a process must have execute (search) permission for that directory.
chdir() will work only in the currently active process and only until termination of the active program. chdir() is executed only for POSIX files. 

See also

chroot(), getcwd(), unistd.h.