Top Banner
Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management
41

Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, Second Edition

Chapter 5Linux Filesystem

Management

Page 2: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 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

Page 3: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 3

Objectives (continued)

• 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

Page 4: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 4

The Filesystem Hierarchy Standard

• Filesystem Hierarchy Standard (FHS): Standard set of directories for Linux and UNIX systems– File and subdirectory contents– Gives Linux software developers ability to locate files

on any Linux system• Create non-distribution–specific software

Page 5: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 5

The Filesystem Hierarchy Standard (continued)

Table 5-1: Linux directories defined by FHS

Page 6: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 6

The Filesystem Hierarchy Standard (continued)

Table 5-1 (continued): Linux directories defined by FHS

Page 7: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 7

Managing Files and Directories

• mkdir command: Creates new directories– Arguments specify directory’s absolute or relative

pathname

• mv command: Moves files– Two arguments minimum:

• Source file/directory (may specify multiple sources)

• Target file/directory

– Also used to rename files

Page 8: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 8

Managing Files and Directories (continued)

• cp command: Copies files– Same arguments as mv command

• Recursive: Referring to itself and its own contents– Recursive search includes all subdirectories in a

directory and their contents– –r option

Page 9: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 9

Managing Files and Directories (continued)

• interactive mode: Prompts user before overwriting files– –i option– –f option: Overrides interactive mode

• rm command: Removes files

– Arguments are a list of files

• rmdir command: Removes directories– –r and –f options are helpful

Page 10: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 10

Managing Files and Directories (continued)

Table 5-2: Common Linux file management commands

Page 11: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 11

Finding Files

• locate command: Search for files on system– Shortcut to the slocate command– Information returned may not fit on screen

• Use with more or less commands

– Uses indexed database of all files on system

• Find command: Recursively search for files starting from a specified directory

Page 12: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 12

Finding Files (continued)

Table 5-3: Common criteria used with find command

Page 13: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 13

Finding Files (continued)

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

Page 14: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 14

Finding Files (continued)

• which command: Search for an executable file– Searches the PATH variable

• PATH variable: Lists directories on system where executable files are located – Allows executable files to be run without specifying

absolute or relative path

Page 15: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 15

Linking Files

• Symbolic link: One file is a pointer or shortcut to another

• Hard link: Two files share the same data

Page 16: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 16

Linking Files (continued)

• Filesystem has three main structural sections:– Superblock: Contains general information about the

filesystem • e.g., number of inodes and data blocks

– Inode: Describes a file or directory• Unique inode number, file size, data block locations,

last date modified, permissions, and ownership

• Inode table: Consists of several inodes– Data blocks: Data making up contents of a file

Page 17: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 17

Linking Files (continued)

Figure 5-1: The structure of hard linked files

Page 18: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 18

Linking Files (continued)

• ln (link) command: Create hard and symbolic links– Two arguments:

• Existing file to link

• Target file to create as a link to existing file

– Use –s option to create symbolic link

• Hard linked files share two inodes

• Data blocks in symbolically linked files contain pathname to target file

Page 19: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 19

Linking Files (continued)

Figure 5-2: The structure of symbolically linked files

Page 20: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 20

File and Directory Permissions

• All users must login with a username and password

• Users identified by username and group memberships– Access to resources depends on username and

group membership– Must have required permissions

Page 21: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 21

File and Directory Ownership

• Primary group: User’s default group

• During file creation, file’s owner and group owner set to user’s username and primary group– Same for directory creation

• touch command: Create an empty file

Page 22: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 22

File and Directory Ownership (continued)

• chown (change owner) command: Change ownership of a file or directory

• chgrp (change group) command: Change group owner of a file or directory

Page 23: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 23

Managing File and Directory Permissions

• Mode: Inode Section that stores permissions • Three sections, based on the user(s) that receive

the permission:– User permissions: Owner– Group permissions: Group owner– Other permissions: Everyone on system

• Three regular permissions may be assigned to each user:– Read– Write– Execute

Page 24: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 24

Interpreting the Mode

Figure 5-3: The structure of a mode

Page 25: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 25

Interpreting the Mode (continued)

• User: Refers to owner of a file or directory• Owner: Refers to users with ability to change

permissions on a file or directory• Other: Refers to all users on system

• Shell scripts: Text files containing instructions for the shell to execute

Page 26: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 26

Interpreting Permissions

Table 5-4: Linux permissions

Page 27: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 27

Changing Permissions

• chmod (change mode) command: Change mode (permissions) of files or directories

• Permissions stored in a file’s or a directory’s inode as binary powers of two

Page 28: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 28

Changing Permissions (continued)

Table 5-5: Criteria used within the chmod command

Page 29: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 29

Changing Permissions (continued)

Figure 5-4: Numeric representation of the mode

Page 30: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 30

Changing Permissions (continued)

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

Page 31: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 31

Default Permissions

• New files given rw-rw-rw- permissions by default

• umask: Takes away permissions on new files and directories

• umask command: Displays the umask

• Changing the umask– Use a new umask as an argument to the umask

command

Page 32: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 32

Default Permissions (continued)

Figure 5-5: Performing a umask 022 calculation

Page 33: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 33

Default Permissions (continued)

Figure 5-6: Performing a umask 007 calculation

Page 34: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 34

Special Permissions

• SUID (Set User ID)

• SGID (Set Group ID)

• Sticky bit

Page 35: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 35

Defining Special Permissions

• SUID – If set on a file, user who executes the file becomes

owner of the file during execution– No functionality when set on a directory– Only applicable to binary compiled programs

Page 36: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 36

Defining Special Permissions (continued)

• SGID– Applicable to files and directories– If set on a file, user who executes the file becomes

member of the file’s group during execution– If a user creates a file in a directory with SGID set,

the directory’s group owner is changed to match the file’s group owner

Page 37: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 37

Defining Special Permissions (continued)

• Sticky bit – Previously used to lock files in memory– Currently only applicable to directories– Ensures that a user can only delete files his/her own

files

Page 38: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 38

Setting Special Permissions

• Special permissions require execute

• Mask the execute permission when displayed by the ls –l command

• May be set even if file or directory does not have execute permission– Via chmod command

• Add an extra digit at front of permissions argument

Page 39: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 39

Setting Special Permissions (continued)

Figure 5-7: Representing special permissions in the mode

Page 40: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 40

Setting Special Permissions (continued)

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

Page 41: Linux+ Guide to Linux Certification, Second Edition Chapter 5 Linux Filesystem Management.

Linux+ Guide to Linux Certification, 2e 41

Setting Special Permissions (continued)

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