+ All Categories
Home > Documents > Week 4 Linux File System Management. Objectives Find files and directories on the filesystem ...

Week 4 Linux File System Management. Objectives Find files and directories on the filesystem ...

Date post: 13-Dec-2015
Category:
Upload: samantha-rich
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
49
Week 4 Linux File System Management
Transcript
Page 1: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Week 4Linux File System Management

Page 2: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Linux+ Guide to Linux Certification, 3e 3

Page 4: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

The Filesystem Hierarchy Standard Filesystem Hierarchy Standard (FHS):

standard set of directories for Linux and UNIX systemsStandard file and subdirectory contentsSimplifies the task of finding specific filesGives 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: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

The Filesystem Hierarchy Standard (continued)

Linux+ Guide to Linux Certification, 3e 5

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

Page 6: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

The Filesystem Hierarchy Standard (continued)

Linux+ Guide to Linux Certification, 3e 6

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

Page 7: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Managing Files and Directories mkdir command: creates new directories

Arguments specify directory’s absolute or relative pathname

mv command: moves filesMinimum of two arguments:

○ Source file/directory (may specify multiple sources)

○ Target file/directoryPathnames can be absolute or relative

○ For multiple files, can use wildcards in pathnameAlso used to rename files or directories

Linux+ Guide to Linux Certification, 3e 7

Page 8: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Managing Files and Directories (continued) cp command: copies files

Same arguments as the mv commandAlso used to make copies of files

Recursive: referring to itself and its own contentsRecursive copy command copies the

directory and all subdirectories and contentsRecursive search includes all subdirectories

in a directory and their contentsUse –r option

Linux+ Guide to Linux Certification, 3e 8

Page 9: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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 filesCan use wildcardsInteractive mode by default

○ Use -f option to override

Linux+ Guide to Linux Certification, 3e 9

Page 10: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Managing Files and Directories (continued) rmdir command: removes directories

Arguments are a list of filesCan use wildcardsInteractive mode by default

○ Use -f option to overrideCannot be used to remove directory full of

files○ To delete directory and all its contents

(subdirectories and files), use rm –r command

Linux+ Guide to Linux Certification, 3e 10

Page 11: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Managing Files and Directories (continued)

Linux+ Guide to Linux Certification, 3e 11

Table 4-2: Common Linux file management commands

Page 12: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Finding Files

locate command: Search for files on systemReceives full or partial filename as argumentUses premade indexed database of all files

on system○ To update the database use updatedb

commandInformation returned may not fit on screen

○ Use with more or less commands

Linux+ Guide to Linux Certification, 3e 12

Page 13: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Finding Files (continued) find command: recursively search for files

starting from a specified directorySlower than locate command, but more versatileFormat: 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

Linux+ Guide to Linux Certification, 3e 13

Page 14: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Finding Files (continued)

Linux+ Guide to Linux Certification, 3e 14

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

Page 15: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Finding Files (continued)

Linux+ Guide to Linux Certification, 3e 15

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

Page 16: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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 fileSearches the PATH variableIf the file is not found, lists the directories

that were searched

Linux+ Guide to Linux Certification, 3e 16

Page 17: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

What is an INODE? Inodes store information about files and folders, such as file

ownership, access mode (read, write, execute permissions), and file type.

Fixed number of inodes per file system Inodes do not contain file names, only file metadata. Use df -i to see inode usage Use ls -i to determine a filenames inode number

WARNING: You can use up all of a filesystems inodes without using all of the storage space on the disk it resides.

Linux+ Guide to Linux Certification, 3e 17

Page 18: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Linking Files

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

Hard link: two files share the same data

Linux+ Guide to Linux Certification, 3e 18

Page 19: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Linux+ Guide to Linux Certification, 3e 19

Page 20: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Linking Files (continued)

Hard linked files share the same inode and inode numberMust reside on the same filesystem

To remove hard linked files, delete one of the linked filesReduces the link count for the file

Linux+ Guide to Linux Certification, 3e 20

Page 21: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Linking Files (continued)

21Linux+ Guide to Linux Certification, 3e

Figure 4-1: The structure of hard linked files

Page 22: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Linux+ Guide to Linux Certification, 3e 22

Page 23: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Linking Files (continued)

Linux+ Guide to Linux Certification, 3e 23

Figure 4-2: The structure of symbolically linked files

Page 24: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Linking Files (continued)

ln (link) command: Create hard and symbolic linksTwo arguments:

○ Existing file to link○ Target file to create as a link to existing file

Use –s option to create symbolic linkArguments can be relative or absolute

pathnames

Linux+ Guide to Linux Certification, 3e 24

Page 25: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

File and Directory Permissions All users must login with a username

and password Users identified by username and group

membershipsAccess to resources depends on username

and group membershipMust have required permissions

Linux+ Guide to Linux Certification, 3e 25

Page 26: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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 groupSame for directory creation

whoami command: view current user name groups command: view group

memberships and primary group touch command: create an empty file

Linux+ Guide to Linux Certification, 3e 26

Page 27: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

File and Directory Ownership (continued) chown (change owner) command:

change ownership of a file or directoryTwo 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 directorySame arguments and options as for chown

command

Linux+ Guide to Linux Certification, 3e 27

Page 28: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Managing File and Directory Permissions Mode: inode section that stores

permissions Three sections, based on the user(s) that

receive the permission:User permissions: ownerGroup permissions: group ownerOther permissions: everyone on system

Three regular permissions may be assigned to each user:ReadWriteExecute

Linux+ Guide to Linux Certification, 3e 28

Page 29: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Interpreting the Mode

29Linux+ Guide to Linux Certification, 3e

Figure 4-3: The structure of a mode

Page 30: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Linux+ Guide to Linux Certification, 3e 30

Page 31: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Interpreting Permissions

Linux+ Guide to Linux Certification, 3e 31

Table 4-4: Linux permissions

Page 32: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Changing Permissions

chmod (change mode) command: change mode (permissions) of files or directoriesTwo 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

Linux+ Guide to Linux Certification, 3e 32

Page 33: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Changing Permissions (continued)

33Linux+ Guide to Linux Certification, 3e

Table 4-5: Criteria used within the chmod command

Page 34: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Changing Permissions (continued)

Linux+ Guide to Linux Certification, 3e 34

Figure 4-4: Numeric representation of the mode

Page 35: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Changing Permissions (continued)

Linux+ Guide to Linux Certification, 3e 35

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

Page 36: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Linux+ Guide to Linux Certification, 3e 36

Page 37: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Default Permissions (continued)

37Linux+ Guide to Linux Certification, 3e

Figure 4-5: Performing a umask 022 calculation

Page 38: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Default Permissions (continued)

38Linux+ Guide to Linux Certification, 3e

Figure 4-6: Performing a umask 007 calculation

Page 39: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Special Permissions

Three more optional special permissions for files and directoriesSUID (Set User ID)SGID (Set Group ID)Sticky bit

Linux+ Guide to Linux Certification, 3e 39

Page 40: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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 directoryOnly applicable to binary compiled programs

○ Cannot be used on shell scripts

Linux+ Guide to Linux Certification, 3e 40

Page 41: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Defining Special Permissions (continued) SGID

Applicable to files and directoriesIf 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

Linux+ Guide to Linux Certification, 3e 41

Page 42: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Defining Special Permissions (continued) Sticky bit

Previously used to lock files in memoryCurrently only applicable to directoriesEnsures that a user can only delete his/her

own files when given write permissions in a directory

Linux+ Guide to Linux Certification, 3e 42

Page 43: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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

Add special permissions via chmod commandAdd an extra digit at front of permissions

argument

Linux+ Guide to Linux Certification, 3e 43

Page 44: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Setting Special Permissions (continued)

Linux+ Guide to Linux Certification, 3e 44

Figure 4-7: Representing special permissions in the mode

Page 45: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Setting Special Permissions (continued)

Linux+ Guide to Linux Certification, 3e 45

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

Page 46: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Setting Special Permissions (continued)

46Linux+ Guide to Linux Certification, 3e

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

Page 47: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Summary

The Linux directory tree obeys the FHSAllows system files to be located in standard

directories

Many file management commands exist Can find files using different commands

locate: search preindexed databasewhich: search PATH variablefind: search for file based on criteria

Linux+ Guide to Linux Certification, 3e 47

Page 48: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

Summary (continued) Files can be created as pointers to another

file or as a linked duplicate of another fileCalled symbolic and hard links, respectively

Each file and directory has an owner and a group ownerOwner 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)

Linux+ Guide to Linux Certification, 3e 48

Page 49: Week 4 Linux File System Management. Objectives  Find files and directories on the filesystem  Understand and create linked files  Explain the function.

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 filesystemRoot user can change the ownership of any file

or directory on the Linux filesystem

Linux+ Guide to Linux Certification, 3e 49


Recommended