linux certification ch. 4 ppt

48
Linux+ Guide to Linux Certification, Third Edition Chapter 4 Linux Filesystem Management

Upload: phlabsta

Post on 26-Nov-2015

60 views

Category:

Documents


6 download

DESCRIPTION

Linux Certification Ch. 4 PPT

TRANSCRIPT

Page 1: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, Third Edition

Chapter 4Linux Filesystem

Management

Page 2: Linux Certification Ch. 4 PPT

Objectives

• Find files and directories on the filesystem

• Understand and create linked files

• Explain the function of the Filesystem Hierarchy Standard

• Use standard Linux commands to manage files and directories

Linux+ Guide to Linux Certification, 3e 2

Page 3: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 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 Certification Ch. 4 PPT

The Filesystem Hierarchy Standard

• Filesystem Hierarchy Standard (FHS): standard set of directories for Linux and UNIX systems– Standard file and subdirectory contents– Simplifies the task of finding specific files– Gives Linux software developers ability to locate files

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

Linux+ Guide to Linux Certification, 3e 4

Page 5: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 5

The Filesystem Hierarchy Standard (continued)

Table 4-1: Linux directories defined by the Filesystem Hierarchy Standard

Page 6: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 6

The Filesystem Hierarchy Standard (continued)

Table 4-1 (continued): Linux directories defined by the Filesystem Hierarchy Standard

Page 7: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 7

Managing Files and Directories

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

pathname

• mv command: moves files– Minimum of two arguments:

• Source file/directory (may specify multiple sources)

• Target file/directory

– Pathnames can be absolute or relative• For multiple files, can use wildcards in pathname

– Also used to rename files or directories

Page 8: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 8

Managing Files and Directories (continued)

• cp command: copies files– Same arguments as the mv command– Also used to make copies of files

• Recursive: referring to itself and its own contents– Recursive copy command copies the directory and

all subdirectories and contents– Recursive search includes all subdirectories in a

directory and their contents– Use –r option

Page 9: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 9

Managing Files and Directories (continued)

• Interactive mode: Prompts user before overwriting files– –i option– –f option (force): Overrides interactive mode

• rm command: Removes files

– Arguments are a list of files– Can use wildcards– Interactive mode by default

• Use -f option to override

Page 10: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 10

Managing Files and Directories (continued)

• rmdir command: removes directories– Arguments are a list of files– Can use wildcards– Interactive mode by default

• Use -f option to override

– Cannot be used to remove directory full of files• To delete directory and all its contents (subdirectories

and files), use rm –r command

Page 11: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 11

Managing Files and Directories (continued)

Table 4-2: Common Linux file management commands

Page 12: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 12

Finding Files

• locate command: Search for files on system– Receives full or partial filename as argument– Uses premade indexed database of all files on

system• To update the database use updatedb command

– Information returned may not fit on screen• Use with more or less commands

Page 13: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 13

Finding Files (continued)

• find command: recursively search for files starting from a specified directory– Slower than locate command, but more versatile– Format: find <start directory> -criteria <what to find>

• e.g., find /root –name project

– If using wildcard metacharacters, ensure that they are interpreted by the find command

• Place wildcards in quotation marks

– To reduce search time, specify subdirectory to be searched

Page 14: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 14

Finding Files (continued)

Table 4-3: Common criteria used with the find command

Page 15: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 15

Finding Files (continued)

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

Page 16: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 16

Finding Files (continued)

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

absolute or relative path

• which command: search for an executable file– Searches the PATH variable– If the file is not found, lists the directories that were

searched

Page 17: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 17

Linking Files

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

• Hard link: two files share the same data

Page 18: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 18

Linking Files (continued)

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

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

data block

– The inode table: consists of several inodes, each of which describes a file or directory

• Unique inode number, file size, data block locations, last date modified, permissions, and ownership

– Data blocks: Data making up contents of a file

Page 19: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 19

Linking Files (continued)

• Hard linked files share the same inode and inode number– Must reside on the same filesystem

• To remove hard linked files, delete one of the linked files– Reduces the link count for the file

Page 20: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 20

Linking Files (continued)

Figure 4-1: The structure of hard linked files

Page 21: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 21

Linking Files (continued)

• Symbolic linked files do not share the same inode and inode number with their target file

• Symbolic linked file is a pointer to the target file– Data blocks in the linked file contain only a

pathname for the target file• Linked file and target file have different sizes

– Editing symbolic linked file actually edits the target file

• If the target file is deleted, symbolic link serves no function

Page 22: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 22

Linking Files (continued)

Figure 4-2: The structure of symbolically linked files

Page 23: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 23

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– Arguments can be relative or absolute pathnames

Page 24: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 24

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 25: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 25

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

• whoami command: view current user name

• groups command: view group memberships and primary group

• touch command: create an empty file

Page 26: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 26

File and Directory Ownership (continued)

• chown (change owner) command: change ownership of a file or directory– Two arguments:

• New owner

• File to change

– Can use –R option for contents of directory

• chgrp (change group) command: change group owner of a file or directory– Same arguments and options as for chown

command

Page 27: Linux Certification Ch. 4 PPT

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

Linux+ Guide to Linux Certification, 3e 27

Page 28: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 28

Interpreting the Mode

Figure 4-3: The structure of a mode

Page 29: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 29

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• Permissions are not additive

Page 30: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 30

Interpreting Permissions

Table 4-4: Linux permissions

Page 31: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 31

Changing Permissions

• chmod (change mode) command: change mode (permissions) of files or directories– Two arguments at minimum

• Criteria used to change permissions

• Filenames to change

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

Page 32: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 32

Changing Permissions (continued)

Table 4-5: Criteria used within the chmod command

Page 33: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 33

Changing Permissions (continued)

Figure 4-4: Numeric representation of the mode

Page 34: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 34

Changing Permissions (continued)

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

Page 35: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 35

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 36: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 36

Default Permissions (continued)

Figure 4-5: Performing a umask 022 calculation

Page 37: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 37

Default Permissions (continued)

Figure 4-6: Performing a umask 007 calculation

Page 38: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 38

Special Permissions

• Three more optional special permissions for files and directories– SUID (Set User ID)– SGID (Set Group ID)– Sticky bit

Page 39: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 39

Defining Special Permissions

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

owner of the file during execution• e.g., ping command

– No functionality when set on a directory– Only applicable to binary compiled programs

• Cannot be used on shell scripts

Page 40: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 40

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 file’s group owner is set to be the directory’s group owner and not the user’s primary group

Page 41: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 41

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 his/her own files

when given write permissions in a directory

Page 42: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 42

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– Indicating letter in the mode will be capitalized

• Add special permissions via chmod command– Add an extra digit at front of permissions argument

Page 43: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 43

Setting Special Permissions (continued)

Figure 4-7: Representing special permissions in the mode

Page 44: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 44

Setting Special Permissions (continued)

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

Page 45: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 45

Setting Special Permissions (continued)

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

Page 46: Linux Certification Ch. 4 PPT

Summary

• The Linux directory tree obeys the FHS– Allows system files to be located in standard

directories

• Many file management commands exist

• Can find files using different commands– locate: search preindexed database– which: search PATH variable– find: search for file based on criteria

Linux+ Guide to Linux Certification, 3e 46

Page 47: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 47

Summary (continued)

• Files can be created as pointers to another file or as a linked duplicate of another file– Called symbolic and hard links, respectively

• Each file and directory has an owner and a group owner– Owner can change permissions and grant ownership

• Permissions can be set on the owner of a file, members of the group of the file, and everyone on the system (other)

Page 48: Linux Certification Ch. 4 PPT

Linux+ Guide to Linux Certification, 3e 48

Summary (continued)

• Three regular file and directory permissions (read, write, execute) and three special file and directory permissions (SUID, SGID, sticky bit)

• Permissions can be changed using chmod

• New files and directories receive default permissions from the system

• The root user has all permissions to all files and directories on the Linux filesystem– Root user can change the ownership of any file or

directory on the Linux filesystem