Linux certification-chapter4(study notes)

in #linux2 years ago

linux.PNG

linux ch4.PNG

The Filesystem Hierarchy Standard (FHS)

  • Is the standard for all Linux and UNIX systems directory structure
  • Check out table 4-1 for directory commands

Managing Files and Directories

  • Always organize files into subdirectories based on file purposes. Use the mkdir command followed by the file name.
  • Use mv command to move directories (mv “source” “location”) to move multiple just add more sources or “source*”
  • Sources with the same name will be overwritten when moved into a new location with the same source name.
  • You can copy files to new locations using the cp command using the same method as mv
  • To copy full directories use -r (recursive) in the command.
  • Use -i in all commands to prevent accidental overwriting of files.
  • Use -f to force override.
  • Remover files or directory use rm or rmdir, no coming back after it has been removed
  • Check out table 4-2 for more commands.
    Finding Files

  • Locate command can be used with the file name
  • Updatedb will update the database just like an index page to a textbook.
  • Pruning is removing directories, files, or system files from being indexed
  • Find command can be used to search in a directory tree, list the directory, criteria and what to find
  • Check table 4-3 for more commands
  • Executable files can be found faster using the which command
  • A variable called PATH is placed into memory each time you log into linux
  • PATH lists directories of executable files.
  • Alternatives to which command is type and whereis
    Linking Files

  • 2 ways to link files, symbolic and hard
  • Symbolic link: shortcut or pointer
  • Hard link: shared data
  • Filesystems have 3 main sections
    -- Superblock: info about the filesystem
    -- Inode table: consists of information nodes that describe file or directory in the filesystem, contain a unique inode number
    -- Data blocks: allocation of units where the data is stored, used disk space.
  • Hard link files share the same inode number, thus the same data blocks
  • Symbolic links do not share the same inode and data blocks, just points to the other file

File and Directory Permissions

  • File and directory ownership
    -- 2 users have permissions to modify a file, owner of the file and root
    -- Use whoami and groups for more information about the user.
    -- Use chown to change ownership of a file.
    -- Regular user can not get back ownership once it is changed
    -- Use chgrp command to change the group owner
  • Managing files and directory permissions
    -- Stored permissions is called mode, inside the inode.
    -- This is split into 3 sections, user, group, other
    -- Each of these sections can be assigned read(r), write(w) and execute(x).
    -- Mode{User(rwx)group(rwx)other(rwx)}
    -- Unavailable permission will look like - r - - - w - - - x
    -- Check table 4-4
    -- Changing permissions
    --- Use the chmod command to change permissions
    --- Check table 4-5 for more info
    --- Permissions are stored in binary powers of 2 inside the inode
    --- See table 4-6
    --- Example “chmod 450 file1”
  • Default permissions
    -- Umask takes away permissions after a new file is created
    -- Most common unmask is 022
    -- “0” nothing taken away from user, “2” write is taken away from group and other
  • Special permissions
    -- 3 special permissions, SUID, SGID, Sticky bit
    -- SUID(file only): who executes the file becomes the owner temporarily
    -- Example passwd command
    -- SGID(file and dir): allows a user to become part of the group during execution of file
    -- Sticky bit: allow user to add files and delete the files they have created
    -- Check figure 4-9
  • Setting custom permissions in the ACL
    -- Access control list(ACL): is a list of users or groups with assigned permissions
    -- Use the setfacl command (set file acl)
    -- Use getfacl to view all user and group permissions
    -- The mask is made equal to the least restrictive permission assigned, used to easily revoke permissions on new users and groups added.
    -- Managing filesystem attributes:
    --- Use lsattr to view attributes of a file system
    --- To add or change use chattr command

Chapter Summary

credit: view image copyright details

•  The Linux directory tree obeys the Filesystem Hierarchy Standard, which allows Linux users and developers to locate system files in standard directories.
•  Many file management commands are designed to create, change the location of, or remove files and directories. The most common of these include cp, mv, rm, rmdir, and mkdir.
•  You can find files on the filesystem using a preindexed database (the locate command) or by searching the directories listed in the PATH variable (the which command). However, the most versatile command used to find files is the find command, which searches for files based on a wide range of criteria.
•  Files can be linked two ways. In a symbolic link, one file serves as a pointer to another file. In a hard link, one file is a linked duplicate of another file.
•  Each file and directory has an owner and a group owner. In the absence of system restrictions, the owner of the file or directory can change permissions and give ownership to others.
•  Permissions can be set on the user or owner of a file, members of the group of the file, as well as everyone on the system (other).
•  There are three regular file and directory permissions (read, write, and execute) and three special file and directory permissions (SUID, SGID, and sticky bit). The definitions of these permissions are different for files and directories.
•  Permissions can be changed using the chmod command by specifying symbols or numbers to represent the changed permissions.
•  To ensure security, new files and directories receive default permissions from the system, less the value of the umask variable.
•  The root user has all permissions to all files and directories on the Linux filesystem. Similarly, the root user can change the ownership of any file or directory on the Linux filesystem.
•  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