Advanced Programming in the
UNIX Environment

by W. Richard Stevens
Addison-Wesley Professional Computing Series
0-201-56317-7 * Hardcover * 768 pages * ©1992
[Buy this book]

Chapter 4. Files and Directories

Introduction * stat, fstat, and lstat Functions * File Types * Set-User-ID and Set-Group-ID * File Access Permissions * Ownership of New Files and Directories * access Function * umask Function * chmod and fchmod Functions * Sticky Bit * chown, fchown, and lchown Functions * File Size * File Truncation * Filesystems * link, unlink, remove, and rename Functions * Symbolic Links * symlink and readlink Functions * File Times * utime Function * mkdir and rmdir Functions * Reading Directories * chdir, fchdir, and getcwd Functions * Special Device Files * sync and fsync Functions * Summary of File Access Permission Bits * Summary

Example Relevant Functions
4.1 Print file types (directory, symlink, device etc.) lstat
4.2 Check file access permissions access, open
4.3 Unmasking file permission bits during file creation umask, creat
4.4 Change file permissions (modes) stat, chmod
4.5 Remove (unlink) a file unlink, open
4.6 Truncate file to zero length leaving modified dates intact stat, open (w/ O_TRUNC), utime
4.7 mini "find": Traverse a directory tree + counting file types lstat, opendir, readdir, closedir,
strcmp, strcpy
4.8 Change directory chdir
4.9 Change directory + Print current directory chdir, getcwd
4.10 Print device driver numbers (major + minor) lstat (st_dev, st_rdev)

[Buy this book]