0% found this document useful (0 votes)
41 views42 pages

Eckert5e ch04

The chapter discusses Linux filesystem management. It covers objectives like finding and managing files and directories using commands like mkdir, mv, cp, rm, and locate. It explains the Filesystem Hierarchy Standard and linking files, including the difference between hard links and symbolic links. Managing permissions and ownership of files and directories is also discussed.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views42 pages

Eckert5e ch04

The chapter discusses Linux filesystem management. It covers objectives like finding and managing files and directories using commands like mkdir, mv, cp, rm, and locate. It explains the Filesystem Hierarchy Standard and linking files, including the difference between hard links and symbolic links. Managing permissions and ownership of files and directories is also discussed.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Chapter 4

Linux Filesystem Management

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. M
ay not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Objectives
• After completing this chapter, you will be able to:
• 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
• 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
• Modify the default access control list (ACL)
• View and set filesystem attributes

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The Filesystem Hierarchy Standard
• 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Files and Directories (1 of 5)
• The mkdir (make directory) command: creates new directories
• Arguments specify directory’s absolute or relative pathname
• The mv (move) command: moves files
• Minimum of two arguments
• Source file/directory
• Target file/directory
• Pathnames can be absolute or relative
• For multiple files, can use wildcards in pathname
• Also used to rename files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Files and Directories (2 of 5)
• The cp (copy) command: copies files
• Same arguments as the mv command
• Also used to make copies of files
• To copy a directory full of files, you must tell the cp command that
the copy will be recursive
• Copies files and subdirectories
• Use –r option

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Files and Directories (3 of 5)
• The target is a file that exists
• Both the mv and cp commands warn the user that the target file will be
overwritten and will ask whether to continue
• A feature of the default configuration in Fedora Linux because the BASH
shell contains aliases to the cp and mv commands
• To see the aliases present in the current shell, type alias at the
prompt

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Files and Directories (4 of 5)
• Interactive mode: prompts user before overwriting files
• –f option (force): overrides interactive mode
• The rm (remove) command: removes files
• Arguments are a list of files
• Can use wildcards
• Interactive mode by default
• Use -f option to override
• The rmdir (remove directory) command: removes directories
• Only removes a directory if it contains no files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Files and Directories (5 of 5)
Table 4-2: Common Linux file
management command
Command Description
mkdir Creates directories
rmdir Removes empty directories
mv Moves/renames files and directories
cp Copies files and directories full of files (with the –r or –R option)
alias Displays BASH shell aliases
rm Removes files and directories full of files (with the –r or –R option)
unlink Removes files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Finding Files (1 of 3)
• The locate command: search for files in the Linux directory tree
• Looks in a premade indexed database of all files on system
• To update the database use the updatedb command
• Information returned may not fit on screen
• Use with more or less commands

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Finding Files (2 of 3)
• The 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>
• 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Finding Files (3 of 3)
• PATH variable: lists directories on system where executable files
are located
• Allows executable files to be run without specifying absolute or relative
path
• The which command: search for an executable file
• Searches the PATH variable
• If the file is not found, lists the directories that were searched
• Alternatives: type command and whereis command

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (1 of 7)
• Files can be linked to one another
• Symbolic link (symlink): one file is a pointer or shortcut to another
• Hard link: two files share the same data
• To better understand how files are linked, you must understand
how files are stored on a filesystem
• Superblock
• Inode table
• Data blocks

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (2 of 7)
• Superblock: contains information about the filesystem
• Number of inodes and data blocks
• Size of each data block
• The inode table: consists of several inodes
• Each describes a file or directory and contains a unique inode number for
identification
• The inode stores file size, data block locations, last date modified,
permissions, and ownership
• Data blocks: data making up contents of a file
• Referenced by the inode

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (3 of 7)
• Hard linked files share the same inode and inode number
• Must reside on the same filesystem
• To create a hard link, use the ln (link) command and specify two
arguments
• The existing file to hard-link and the target file that will be created as a
hard link to the existing file
• To remove hard linked files, delete one of the linked files
• Reduces the link count for the file

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (4 of 7)

Figure 4-1: The structure of hard linked files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (5 of 7)
• Symbolic linked files do not share the same inode and data
blocks with their target file
• Symbolic linked file is a pointer to the target file
• Data blocks in the linked file contain only a pathname to the target file
• Editing a symbolic linked file actually edits the target file
• If the target file is deleted, symbolic link serves no function

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (6 of 7)

Figure 4-2: The structure of symbolically linked files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Linking Files (7 of 7)
• To create a symbolic link, use the -s option with the ln command
• Arguments can be relative or absolute pathnames, as with hard links
• Use the ls -l command to view both hard link and symbolic link files
• Symbolic links need not reside on the same filesystem as their target

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
File and Directory Ownership (1 of 2)
• During file creation, that user’s name and primary group becomes
the owner and group owner of the file
• Same for directory creation
• The whoami command: views current user name
• The groups command: views group memberships and primary
group
• The touch command: creates an empty file

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
File and Directory Ownership (2 of 2)
• The chown (change owner) command: change ownership of a file
or directory
• Two arguments
• New owner
• File or directory to change
• Can use –R option to change permissions recursively throughout the
directory tree
• The chgrp (change group) command: change group owner of a
file or directory
• Same arguments and options as for chown command

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing File and Directory Permissions
• Mode: inode section that stores permissions
• User permissions: owner
• Group permissions: group owner
• Other permissions: everyone on system
• Three regular permissions may be assigned to each user
• Read
• Write
• Execute

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Interpreting the Mode (1 of 2)

Figure 4-3: The structure of a mode

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Interpreting the Mode (2 of 2)
• User or owner: refers to users with read, write, and execute
permission
• Other: refers to all users on system
• Permissions are not additive
• The system assigns the first set of permissions that are matched in the
mode order: user, group, other
• Linux permission should not be assigned to other only

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Interpreting Permissions

Table 4-4 : Linux


permissions
Permission Definition for files Definition for files
Read Allows a user to open and read Allows a user to list the contents of the
the contents of a file directory (if the user has also been
given execute permission)
Write Allows a user to open, read, and Allows a user to add or remove files to
edit the contents of a file and from the directory (if the user has
also been given execute permission)
Execute Allows a user to execute the file Allows a user to enter the directory and
in memory (if it is a program file work with directory contents
or script)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Changing Permissions (1 of 3)
• The chmod (change mode) command: change mode
(permissions) of files or directories
• Takes two arguments at minimum
• Criteria used to change permissions
• Filenames to change
• If the permissions to be changed are identical for the user, group, and
other categories, you can use the “a” character to refer to all categories

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Changing Permissions (2 of 3)
Table 4-5: Criteria used
within the chmod command

Category Operation Permission

u (user) + (adds a permission) r (read)

g (group) - (removes a permission) w (write)

o (other) = (makes a permission equal to) x (execute)

a (all categories)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Changing Permissions (3 of 3)

Figure 4-4: Numeric representation of the mode

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Default Permissions (1 of 2)
• New files are given rw-rw-rw- permissions by default
• The umask variable: a special variable that takes away
permissions on new files and directories
• The umask command: displays the umask
• Changing the umask: se a new umask as an argument to the
umask command

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Default Permissions (2 of 2)

Figure 4-6: Performing a umask 007 calculation

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Special Permissions
• Three more optional special permissions for files and directories
• SUID (Set User ID)
• SGID (Set Group ID)
• Sticky bit

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Defining Special Permissions (1 of 3)
• If SUID is set on a file, user who executes the file becomes owner
of the file during execution (e.g., passwd command)
• No special functionality when set on a directory
• Only applicable to binary compiled programs
• Cannot be used on shell scripts

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Defining Special Permissions (2 of 3)
• 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Defining Special Permissions (3 of 3)
• 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Setting Special Permissions (1 of 3)
• Special permissions require execute
• They 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Setting Special Permissions (2 of 3)

Figure 4-7: Representing special permissions in the mode

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Setting Special Permissions (3 of 3)

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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Setting Custom Permissions in the Access
Control List (ACL)
• Access control list (ACL): a list of users or groups that you can
assign permissions
• The setfacl (set file ACL) command: used to modify ACL entries
for a particular Linux file or directory
• Use the -m option to modify the ACL
• Use the -b option to remove all extra ACL assignments on a particular file
or directory
• The getfacl (get file ACL) command: used to list all additional
entries in the ACL

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Filesystem Attributes
• Linux has file attributes that can be set; work outside Linux
permissions and are filesystem-specific
• The lsattr (list attributes) command: used to list filesystem
attributes
• The chattr (change attributes) command: used to add or remove
filesystem attributes
• Immutable attribute (i): prevents the file from being modified in
any way

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (1 of 3)
• The Linux directory tree obeys the Filesystem Hierarchy Standard
• Allows system files to be located in standard directories
• Many file management commands exist
• Create, change the location of, or remove files
• You can find files using different commands
• locate: search preindexed database
• which: search PATH variable
• find: search for file based on criteria

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (2 of 3)
• Files can be linked two different ways
• Symbolic link: a file serves as a pointer to another
• Hard links: one file is a linked duplicate of another
• 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)
• There are three regular file and directory permissions (read, write,
execute) and three special file and directory permissions (SUID,
SGID, sticky bit)
Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (3 of 3)
• Permissions can be changed using chmod command
• New files and directories receive default permissions
• 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
• The default ACL on a file or directory can be modified to include
additional users or groups
• Filesystem attributes can be set on Linux files to provide low-level
functionality such as immutability

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like