Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

18. Directories and Links > Creating and Removing Directories: mkdir() and rmdi...

Creating and Removing Directories: mkdir() and rmdir()

The mkdir() system call creates a new directory.

#include <sys/stat.h>

int mkdir(const char *pathname, mode_t mode);


Returns 0 on success, or -1 on error

The pathname argument specifies the pathname of the new directory. This pathname may be relative or absolute. If a file with this pathname already exists, then the call fails with the error EEXIST.

The ownership of the new directory is set according to the rules described in Ownership of New Files.

The mode argument specifies the permissions for the new directory. (We describe the meanings of the permission bits for directories in Ownership of New Files, Changing File Ownership: chown(), fchown(), and lchown() , and Set-User-ID, Set-Group-ID, and Sticky Bits.) This bit-mask value may be specified by ORing (|) together constants from Table 15-4, in Permissions on Directories, but, as with open(), it may also be specified as an octal number. The value given in mode is ANDed against the process umask (The Process File Mode Creation Mask: umask() ). In addition, the set-user-ID bit (S_ISUID) is always turned off, since it has no meaning for directories.


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint