Linux Guide to Linux Certification Chapter Five Linux

  • Slides: 45
Download presentation
Linux+ Guide to Linux Certification Chapter Five Linux Filesystem Management

Linux+ Guide to Linux Certification Chapter Five Linux Filesystem Management

Objectives • Explain the function of the Filesystem Hierarchy Standard • Use standard Linux

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 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

The Filesystem Hierarchy Standard (FHS) • FHS – Standard of outlining the location of

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

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

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

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

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

Managing Files and Directories • mkdir command – Takes arguments specifying the absolute or

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

Managing Files and Directories • cp command – Command used to create copies of

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

Managing Files and Directories • rm command – Takes a list of arguments specifying

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

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

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

Finding Files • locate command – The fastest method to search for files in

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

Finding Files • find command – Used to find files on the filesystem using

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

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

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

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

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

Finding Files • which command – Command used to locate files that exist within

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

Linking Files • Files may be linked to another in one of two ways:

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)

Linking Files • To better understand how files are linked, you must understand how

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

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

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

Linking Files • ln (link) command – Command used to create hard and symbolic

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

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

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

File and Directory Permissions • Recall that all users must successfully login with a

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

File and Directory Ownership • When a user creates a file or directory, that

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

File and Directory Ownership • touch command – Command used to create new files

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

File and Directory Ownership • chgrp (change group) command – Command to change the

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

Managing File and Directory Permissions • Mode – The section of the inode that

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

Managing File and Directory Permissions • There are three regular permissions that you may

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

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

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

Interpreting the Mode • User – When used in the mode of a certain

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

Interpreting Permissions Table 5 -4: Linux permissions

Interpreting Permissions Table 5 -4: Linux permissions

Changing Permissions • chmod (change mode) command – Used to change the mode (permissions)

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

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

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

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

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

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

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

Default Permissions • Umask – Used to alter the permissions on all new files

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

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

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

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

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

Special Permissions • Read, write, and execute are the regular file permissions used to

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

Defining Special Permissions • The SUID has no special function when set on a

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

Defining Special Permissions • The SGID has a function when applied to both files

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

Setting Special Permissions • The mode of a file that is displayed using the

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

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

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

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

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

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

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

Chapter Summary • The Linux directory tree obeys the Filesystem Hierarchy Standard • The

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 preindexed 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

Chapter Summary • Each file and directory has an owner and a group owner

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

Chapter Summary • Permissions can be changed using the chmod command by specifying symbols

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