1 / 19

File System Related Commands

File System Related Commands. To create a file system (format a secondary storage device) use: mkfs. mkfs - constructs a file system on a device Example: mkfs /dev/fd0. To mount a file system at a given mount point use: mount .

laszlo
Download Presentation

File System Related Commands

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File System Related Commands • To create a file system (format a secondary storage device) use: mkfs. • mkfs - constructs a file system on a device • Example: mkfs /dev/fd0 File system commands and system calls

  2. To mount a file system at a given mount point use: mount. • mount - mounts a file system (umount - unmounts a file system) • Example: mount /dev/fd0 /usr/floppy • Note that /usr/floppy must be a valid path name. File system commands and system calls

  3. To make a new directory use: mkdir • mkdir - creates a new directory • Example: mkdir floppy File system commands and system calls

  4. To delete an existing directory use: rmdir • rmdir - removes existing directory • Example: rmdir floppy File system commands and system calls

  5. File links: hard links A hard link is a pointer to a file and is indistinguishable from the original directory entry. Any changes to a file are effective independent of the name used to reference the file. Hard links may not span file systems and may not refer to directories. File system commands and system calls

  6. Symbolic links A symbolic link is an indirect pointer to a file; its directory entry contains the name of the file to which it is linked. Symbolic links may span file systems and may refer to directories. File system commands and system calls

  7. To create a link use ln ln - make hard or symbolic links to files. Example: ln -s /usr/dorots/myfile /usr/jim/yourfile File system commands and system calls

  8. To add a new user use:adduser. • adduser - adds a new user account. • Example: adduser dorota other /usr/dorota File system commands and system calls

  9. To change an owner of a file use: chown • (reserved to the superuser) • chown - changes the owner of a file (directory) • Example: chown root myfile File system commands and system calls

  10. File System Related System Calls • To find out properties associated with files use fstat system call. #include <sys/types.h> #include <sys/stat.h> int fstat(int fd, struct stat *buff). File system commands and system calls

  11. Example of the use of fstat • if fstat (fd, &pst) { printf("\tDevice %d\n", pst->st_dev); printf("\tInode %u\n", pst->st_ino); printf("\tMode 0%06o\n", pst->st_mode); printf("\tNlink %d\n", pst->st_nlink); printf("\tUID %d\n", pst->st_uid); printf("\tGID %d\n", pst->st_gid); printf("\tRdev %d\n", pst->st_rdev); printf("\tSize %u\n", pst->st_size); printf("\tLast accessed: %s", ctime(&pst->st_atime)); printf("\tLast modified: %s", ctime(&pst->st_mtime)); • printf("\tLast status change: %s", ctime(&pst->st_ctime)) } File system commands and system calls

  12. File status of file descriptor 3 (test.txt): Device 898 /* device number Inode 2780 /* inode number Mode 0100600 /* file mode including Nlink 1 /* number of links UID 10 /* user id of owner GID 0 /* group of owner Rdev 0 /* device type (for device file Size 0 /* file size Last accessed: Tue Feb 9 00:31:10 1999 Last modified: Tue Feb 9 00:31:10 1999 Last status change: Tue Feb 9 00:31:10 1999 File system commands and system calls

  13. access - determine accessibility of a file • #include <unistd.h> • int access(const char *path, int amode); • amode can be: • R_OK Test for read permission. • W_OK Test for write permission. • X_OK Test for execute or search permission. • F_OK Check existence of file File system commands and system calls

  14. chmod - change the permissions mode of a file chmod [ -fR ] <absolute-mode> file.. chmod [ -fR ] <symbolic-mode-list> file... u user's permissions g group's permissions o others' permissions a all permissions (user, group, and other) operator either +, -, or =, signify how permissions are to be changed: File system commands and system calls

  15. r read permission w write permission x execute permission Permissions are described in three sequences each having three characters: User Group Other rwx rwx rwx File system commands and system calls

  16. Examples: chmod a=rwx,g+s file chmod 2777 file Allow everyone to read, write, and execute the file and turn on the set group-ID. File system commands and system calls

  17. Other calls • chown - changes file owner • chroot - changes root directory for a command • dup - duplicates file descriptor for an open file. • fcntl - file control allows to execute a number of commands for a file File system commands and system calls

  18. ioctl - control device, performs a variety of control functions on devices • link, unlink - link and unlink files and directories • pipe- create an interprocess channel (temporary file) • rename - change the name of a file • stime - set system time and date • sync - update the super block File system commands and system calls

  19. File related calls creat - create a file open - open a files close - close a file read - read a file write - write a file lseek - move read/write file pointer File system commands and system calls

More Related