1 / 45

Chapter Five

Chapter Five. Linux Filesystem Management. Objectives. Explain the function of the Filesystem Hierarchy Standard Use standard Linux commands to manage files and directories Find files and directories on the filesystem Understand and create linked files Modify file and directory ownership

Download Presentation

Chapter Five

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. Chapter Five Linux Filesystem Management

  2. Objectives • Explain the function of the Filesystem Hierarchy Standard • Use standard Linux commands to manage files and directories • Find files and directories on the filesystem • Understand and create linked files • Modify file and directory ownership • Define and change Linux file and directory permissions • Identify the default permissions created on files and directories • Apply special file and directory permissions

  3. The Filesystem Hierarchy Standard (FHS) • FHS • Standard of outlining the location of set files and directories on a Linux system • Gives Linux software developers the ability to locate files on a Linux system regardless of the distribution • This allows them to create software that is not distribution specific • A comprehensive understanding of the standard type of directories found on systems is valuable when locating and managing files and directories

  4. The Filesystem Hierarchy Standard (FHS) Table 5-1: Linux directories defined by FHS

  5. The Filesystem Hierarchy Standard (FHS) Table 5-1 (continued): Linux directories defined by FHS

  6. Managing Files and Directories • mkdir command • Takes arguments specifying the absolute or relative pathnames of the directories to create • The mv command requires two arguments at a minimum: • Source file/directory • Target file/directory

  7. Managing Files and Directories • cp command • Command used to create copies of files and directories • Recursive • Referring to itself and its own contents • A recursive search includes all subdirectories in a directory and their contents

  8. Managing Files and Directories • rm command • Takes a list of arguments specifying the absolute or relative pathname of files to remove • rmdir command • Command used to empty directories

  9. Managing Files and Directories Table 5-2: Common Linux file management commands

  10. Finding Files • locate command • The fastest method to search for files in the Linux directory tree • A shortcut to the slocate (or secure locate) command • Often returns too much information to display on the screen, as it searches all files on the filesystem

  11. Finding Files • find command • Used to find files on the filesystem using various criteria • Does not use a pre-made index of files • Searches the directory tree recursively, starting from a certain directory, for files that meet a certain criteria

  12. Finding Files Table 5-3: Common criteria used with find command

  13. Finding Files Table 5-3 (continued): Common criteria used with find command

  14. Finding Files • which command • Command used to locate files that exist within directories listed in the PATH variable • PATH variable • Stores a list of directories that will be searched in order when commands are executed without an absolute or relative pathname

  15. Linking Files • Files may be linked to another in one of two ways: • One file may simply be a pointer or a shortcut to another file (known as a symbolic link or symlink) • The two files may share the same data (known as a hard link)

  16. Linking Files • To better understand how files are linked, you must understand how files are stored on a filesystem • On a structural level, a filesystem has three main sections: • The superblock • The inode table • Data blocks

  17. Linking Files Figure 5-1: The structure of hard linked files

  18. Linking Files • ln (link) command • Command used to create hard and symbolic links • To create hard link, you must use the ln command and specify two arguments: • The existing file to hard-link • The target file that will be created as a hard link to the existing file

  19. Linking Files Figure 5-2: The structure of symbolically linked files

  20. File and Directory Permissions • Recall that all users must successfully login with a username and password to gain access to a Linux system • Once logged in, users are identified by their username and group memberships • All access to resources depends on whether their username and group membership have the required permission

  21. File and Directory Ownership • When a user creates a file or directory, that user’s name and primary group become the owner and group owner of the file, respectively • Primary group • Default group to which a user belongs

  22. File and Directory Ownership • touch command • Command used to create new files • Originally used to update the timestamp on a file • chown (change owner) command • Command used to change the owner and group owner of a file or directory

  23. File and Directory Ownership • chgrp (change group) command • Command to change the group owner of a file or directory • Takes two arguments at a minimum: • The new group owner • The files or directories to change

  24. Managing File and Directory Permissions • Mode • The section of the inode that stores permissions • Divided into three sections based on the user(s) that receive(s) the permission to that file or directory • User (owner) permissions • Group (group owner) permissions • Other (everyone on the Linux system permissions

  25. Managing File and Directory Permissions • There are three regular permissions that you may assign to each of the user(s) referenced on the previous slide: • Read • Write • Execute

  26. Interpreting the Mode Figure 5-3: The structure of a mode

  27. Interpreting the Mode • User • When used in the mode of a certain file or directory, it refers to the owner of that file or directory • Owner • User whose name appears in a long listing of a file or directory and who has the ability to change permissions on that file or directory • Other • When used in the mode of a certain file or directory, it refers to all users on the Linux system

  28. Interpreting Permissions Table 5-4: Linux permissions

  29. Changing Permissions • chmod (change mode) command • Used to change the mode (permissions) of a file or directory • Takes two arguments at a minimum: • The first argument specifies the criteria used to change the permissions • The remaining arguments indicate the filenames to change

  30. Changing Permissions Table 5-5: Criteria used within the chmod command

  31. Changing Permissions Figure 5-4: Numeric representation of the mode

  32. Changing Permissions Table 5-6: Numeric representations of the permissions in a mode

  33. Default Permissions • Umask • Used to alter the permissions on all new files and directories by taking select default file and directory permissions away • Only applies to newly created files and directories • Will never be used to modify the permissions of existing files and directories

  34. Default Permissions Figure 5-5: Performing a umask 007 calculation

  35. Default Permissions Figure 5-6: Performing a umask 007 calculation

  36. Special Permissions • Read, write, and execute are the regular file permissions used to assign security to files • Three more special permissions that you may optionally use on file and directories: • SUID (Set User ID) • SGID (Set Group ID) • Sticky bit

  37. Defining Special Permissions • The SUID has no special function when set on a directory • However, if the SUID is set on a file and that file is executed, then the person who executed the file temporarily becomes the owner of the file while it is executing • The SUID can only be applied to binary compiled programs

  38. Defining Special Permissions • The SGID has a function when applied to both files and directories • The SGID allows regular users to execute a binary compiled program and become a member of the group that is attached to the file during execution of the program • The sticky bit was used on files in the past to lock them in memory • Today, the sticky bit performs a useful function only on directories

  39. Setting Special Permissions • The mode of a file that is displayed using the ls –l command does not have a section for special permissions • Special permissions require execute • They mask the execute permission when displayed using the ls –l command

  40. Setting Special Permissions Figure 5-7: Representing special permissions in the mode

  41. Setting Special Permissions Figure 5-8: Representing special permissions in the absence of the execute permissions

  42. Setting Special Permissions Figure 5-9: Numeric representation of regular and special permissions

  43. Chapter Summary • The Linux directory tree obeys the Filesystem Hierarchy Standard • The re are many file management commands that exist to create, change the location of, or remove files and directories • You may find files on the filesystems using a pre-indexed database, or by searching the directories listed in the PATH variable • Files may be created as a pointer to another file or a as a linked duplicate if another file

  44. Chapter Summary • Each file and directory has an owner and a group owner • Permissions can be set on the user or owner of a file, members of the group of the file, as well as everyone on the system • There are three regular file and directory permissions and three special file and directory permissions

  45. Chapter Summary • Permissions can be changed using the chmod command by specifying symbols or numbers to represent the changed permissions • To ensure security, new files and directories receive default permissions from the system less the value of the umask variable • The root user has all the permissions to all files and directories on the Linux filesystems

More Related