You are on page 1of 51

Linux filesystem management

Unit objectives
 Explain the function of the Filesystem
Course ILT

Hierarchy Standard
 Find files and directories and link files
 Modify file and directory ownership
 Identify the default permissions and
apply special file and directory
permissions
Topic A
 Topic A: The Filesystem Hierarchy
Standard
Course ILT

 Topic B: Searching and linking files


 Topic C: File and directory
permissions
 Topic D: Default and special
permissions
Filesystem Hierarchy Standard
 Outlines standard locations for files
and directories
Course ILT

 Gives software developers a


consistent context regardless of the
distribution
 Helps users of one system work on
another
Course ILT Linux directories defined by FHS
Course ILT FHS: Linux directories
Course ILT Activity A-1

Discussing the FHS directory


structure
Managing files and directories
 mkdir command
– Takes arguments specifying the absolute
Course ILT

or relative pathnames of the directories


to create
Course ILT Activity A-2

Creating new directories


Managing files and directories
 The mv command requires two
arguments at a minimum:
Course ILT

– Source file/directory
– Target file/directory

continued
Managing files and directories, continued

 cp command
– Command used to create copies of files
Course ILT

and directories

continued
Managing files and directories, continued

 rm command
– Takes a list of arguments specifying the
Course ILT

absolute or relative pathname of files to


remove

continued
Managing files and directories, continued

 rmdir command
– Command used to empty directories
Course ILT
Course ILT Activity A-3

Moving files by using


the mv command
Course ILT Activity A-4

Copying files by using the cp


command
Course ILT Activity A-5

Using the rm and rmdir


commands
Topic B
 Topic A: The Filesystem Hierarchy
Standard
Course ILT

 Topic B: Searching and linking files


 Topic C: File and directory
permissions
 Topic D: Default and special
permissions
Finding files
 locate command
– Fastest method to search for files
Course ILT

– A shortcut to the slocate (or secure


locate) command
 find command
– Used to find files using various criteria
– Searches the directory tree recursively,
starting from a certain directory, for files
that meet criteria
which command and PATH variable

 which command
– Used to locate files within directories
Course ILT

listed in the PATH variable


 PATH variable
– Stores list of directories searched when
commands are executed without an
absolute or relative pathname
Course ILT Activity B-1

Using find, locate, and which


commands
Linking files
 On a structural level, a filesystem has
three main sections:
Course ILT

– The superblock
– The inode table
– Data blocks
 Files can be linked two ways
– Symbolic link or symlink, one file a
pointer or a shortcut to another file
– Hard link, two files share the same data
Course ILT Structure of hard linked files
In command
 ln (link) command
– Command used to create hard and
Course ILT

symbolic links
 To create hard link use the ln
command with two arguments:
– The existing file to hard-link
– The target file that will be created as a
hard link to the existing file
Course ILT Structure of symbolically linked files
Course ILT Activity B-2

Making and viewing links to files


and directories
Topic C
 Topic A: The Filesystem Hierarchy
Standard
Course ILT

 Topic B: Searching and linking files


 Topic C: File and directory
permissions
 Topic D: Default and special
permissions
File and directory permissions
 When a user creates a file or
directory, that user’s name and
Course ILT

primary group become the owner and


group owner of the file
 Primary group
– Default group to which a user belongs
chown and chgrp commands
 chown (change owner) command
– Used to change the owner and group
Course ILT

owner of a file or directory


 chgrp (change group) command
– 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
Course ILT Activity C-1

Using chown and chgrp


Managing file and directory permissions

 Mode
– The section of the inode that stores
Course ILT

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
Regular permissions
 There are three regular permissions
that you might assign to a user
Course ILT

– Read
– Write
– Execute
Course ILT The structure of a mode
Course ILT Interpreting permissions
chmod command
 Used to change the mode
(permissions) of a file or directory
Course ILT

 Takes two arguments at a minimum:


– The first specifies criteria used to change
permissions
– The remaining arguments indicate the
filenames to change
Course ILT Criteria used: chmod command
Course ILT Mode: numeric representation
Numeric representations: permissions
Course ILT
Course ILT Activity C-2

Applying and modifying access


permissions
Topic D
 Topic A: The filesystem hierarchy
standard
Course ILT

 Topic B: Searching and linking


 Topic C: File and directory
permissions
 Topic D: Default and special
permissions
Default permissions
 umask
– Used to alter the permissions on all new
Course ILT

files and directories


– Takes select default file and directory
permissions away
– Applies only to newly created files and
directories
 Never used to modify existing files or
directories
Course ILT umask 022 calculation
Course ILT umask 007 calculation
Course ILT Activity D-1

Using the umask variable


Special permissions
 Three special permissions that you
can use on files and directories:
Course ILT

– SUID (Set User ID)


– SGID (Set Group ID)
– Sticky bit
Defining special permissions
 The SUID has no special function
when set on a directory
Course ILT

– 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 be applied only to
binary compiled programs

continued
Defining special permissions, continued

 The SGID has a function when applied


to both files and directories
Course ILT

 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 performs a useful
function only on directories
Setting special permissions
 The mode of a file that is displayed
using the ls –l command does not
Course ILT

have a section for special permissions


 Special permissions require execute
– They mask the execute permission when
displayed using the ls –l command
Course ILT Special permissions in the mode
Course ILT Absence of execute permissions
Course ILT Numeric representation
Course ILT Activity D-2

Viewing and setting special


permissions
Unit summary
 Explained the function of the
Filesystem Hierarchy Standard
Course ILT

 Found files and directories and linked


files
 Modified file and directory ownership
 Identified default permissions and
applied special file and directory
permissions

You might also like