30
Filesystem Hierarchy Standard (FHS) – Standard of outlining the location of set files and directories on a Linux system – Gives Linux software developers the ability to locate files on a Linux system regardless of the distribution •This allows them to create software that is not distribution specific Chapter 9 Part IV Linux Advanced Command Line

Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Embed Size (px)

Citation preview

Page 1: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

• Filesystem Hierarchy Standard (FHS)

– Standard of outlining the location of set files and directories on a Linux system

– Gives Linux software developers the ability to locate files on a Linux system regardless of the distribution• This allows them to create software that is not

distribution specific

Chapter 9 Part IV Linux Advanced Command Line

Page 2: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

The Filesystem Hierarchy Standard (FHS)

Table 5-1: Linux directories defined by FHS

Page 3: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

The Filesystem Hierarchy Standard (FHS)

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

Page 4: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Linking Files

• Files may be linked to another in one of two ways:– One file may simply be a pointer or a shortcut

to another file (known as a symbolic link or symlink)

– The two files may share the same data (known as a hard link)

Page 5: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Linking Files• To better understand how files are linked, you must

understand how files are stored on a filesystem• Structurally, a filesystem has three main sections:

– Superblock: section of info: # of inodes & data blocks – inode table: each inode describes 1 file or directory and

contains a unique inode number for identification• Other info: file size, data block locations, last date modified,

permissions, & ownership• Since directories are files they have an unique inode also

– Data blocks: filename & file contents (data) • Also called allocation units• Directories data blocks contain a list of files located within it

Page 6: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Hard Link Files are direct copies of one another, as they share the same inode & inode number.

The structure of hard linked files

Page 7: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Linking Files

• ln (link) command– Command used to create hard and symbolic links

• To create hard link, you must use the ln command and specify two arguments:– The existing file to hard-link– The target file that will be created as a hard link to the

existing file

Try This: create file1 with touch or one of the editors

$ ls -l i (check parameters. i displays inode)

$ ln file1 file2 (file2 is direct copy)

$ ls –li (have parameters changed?, what about the inode numbers)

Page 8: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Linking Files

Figure 5-2: The structure of symbolically linked files

Symbolic links are sometimes called soft links.

Symbolic links do not share the same inode, they are merely a pointer to the other, thus will have different sizes.

Create file3

$ ln –s file3 file4 (-s symbolic option)

$ ls –li (what’s different, what’s the same?)

$ ls –F (what’s different, what’s the same?)

Page 9: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Listing the Contents of a Folder • The ls command is used to list the contents of a folder and

information about files, by default the current directory.

# ls –al

total 109drwxr-xr-x 18 root root 4096 Jun 9 21:12 ./drwxr-xr-x 18 root root 4096 Jun 9 21:12 ../drwxr-xr-x 2 root root 4096 Jun 9 21:14 bin/drwxr-xr-x 3 root root 1024 Jun 9 20:32 boot/

File type, permissions, hard link count, file owner, group owner, size, mod date, directory name, filename or pointer.

Page 10: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

File and Directory Permissions• Recall that all users must successfully login with a

username and password to gain access to a Linux system

• Once logged in, users are identified by their username and group memberships– All access to resources depends on whether their

username and group membership have the required permission

• When a user creates a file or directory, that user’s name and primary group become the owner and group owner of the file, respectively

• Primary group– Default group to which a user belongs

Page 11: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

File and Directory Ownership• chown (change owner) command

– Command used to change the owner and the group of a file or directory

– Takes two arguments at a minimum:• The new owner and the files or directories to change

$ chown userx file1chgrp (change group) command

– Command to change the group owner of a file or directory– Takes two arguments at a minimum:

• The new group owner and the files or directories to change

$ chgrp sys file1Changing both with chown$ chown userx.sys file1

Page 12: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Managing File and Directory Permissions

Mode– The section of the inode that stores 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

Page 13: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Managing File and Directory Permissions

• There are three regular permissions that you may assign to each of the user(s) referenced on the previous slide:– Read– Write– Execute– And – permission is unavailable

Page 14: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Interpreting the Mode

Figure 5-3: The structure of a mode

Page 15: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Interpreting the Mode

• User or Owner– When used in the mode of a certain file or directory, it

refers to the owner of that file or directory

• User– User whose name appears in a long listing of a file or

directory and who has the ability to change permissions on that file or directory

• Group– Typically users in the same company department

• Other– When used in the mode of a certain file or directory, it

refers to all users on the Linux system

Page 16: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Interpreting Permissions

Table 5-4: Linux permissions

Page 17: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Changing Permissions• chmod (change mode) command

– Used to change the mode (permissions) of a file or dir– Takes two arguments at a minimum:

• The first argument specifies the criteria used to change permissions

• The remaining arguments indicate filenames to change

-rw-r--r--

$ chmod u=rwx,g=rw,o=rw -rwxrw-rw-

$ chmod u+x,g+w,o+w -rwxrw-rw-

$ chmod 766 file1 -rwxrw-rw-

Page 18: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Changing Permissions

Figure 5-4: Numeric representation of the mode

Page 19: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Default Permissions• Umask

– Used to alter the permissions on all new files and directories by taking select default file and directory permissions away

– Only applies to newly created files and directories• Will never be used to modify the permissions of

existing files and directories

Page 20: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Default Permissions

Figure 5-5: Performing a umask 007 calculation

Page 21: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Special Permissions

• Read, write, and execute are the regular file permissions used to assign security to files

• Three more special permissions that you may optionally use on file and directories:– SUID (Set User ID)– SGID (Set Group ID)– Sticky bit

Page 22: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Defining Special Permissions

• The SUID has no special function when set on a directory– 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 only be applied to binary compiled programs

Page 23: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Defining Special Permissions

• The SGID has a function when applied to both files and directories

• 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 was used on files in the past to lock them in memory– Today, the sticky bit performs a useful function only

on directories

Page 24: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Setting Special Permissions

• The mode of a file that is displayed using the ls –l command does not have a section for special permissions

• Special permissions require execute– They mask the execute permission when

displayed using the ls –l command

Page 25: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Setting Special Permissions

Figure 5-7: Representing special permissions in the mode

Page 26: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Setting Special Permissions

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

Page 27: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Setting Special Permissions

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

Page 28: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

The grep Command• grep

– Stands for Global Regular Expression Print– Used to display lines in a text file that match a

certain common regular expression– Search is case sensitive unless –i used– -v reverse meaning of previous command

$ grep “ CIS 130” file5

• Use the egrep command to display lines of text that match extended regular expressions

• The fgrep command does interpret any regular expressions and consequently returns results much faster than the egrep command

Page 29: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Viewing Processes

• There are several Linux utilities that can view processes

• ps command– The most versatile and common Linux utility

that can view processes– Without arguments, the ps command simply

displays a list of processes that are running in the current shell

Page 30: Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers

Viewing Processes

• top command– Most common command used to display

processes aside from ps– Displays its interactive screen listing

processes organized by processor time• Processes that use the most processor time are

listed at the top of the screen