Linux Professional Institute Exam 101 / LPIC 101

Chapter 4

Video 12: Section 103.3 - Basic File Management

- Wildcards (globbing)
    - * = anything
    - ? = any single character
    - ! = not(stuff)
    - [ac] = a OR c
    - [a-c] = a OR b OR c
- Coping
    - # cp {options} {source} {new}
        - [ -R ] = Copying all the content of the folders
- Moving OR renaming
    - # mv {options} {source} {destination}
- Delete/remove
    - # rm {options} {source}
        - [ -i ] = Make the command interactive (confirmation)
        - [ -r ] = Remove a folder and its contents
        - [ -rf ] = Force delete all underlaying files and folders
- Create a empty file OR update editing time
    - # touch {newfile}
- Create a directory
    - # mkdir {newdirectory}
- Remove a empty directory
    - # rmdir {directory}
- Get information about a file
    - # file {source}
- Find files/folders/links etc
    - Goes trough every underplaying folder
    - # find {location} {options}
        - {location} = . = working directory
        - [ -name "{terms}" ] = Find anything with characters {terms}
            - {terms} = characters and wildcarts can be used
        - [ -size {terms} ] = Find anything that matches the {terms}
            - {terms} = +5M = bigger than 5 MB
            - {terms} = -5G = smaler than 5 GB
        - [ -type {terms} ] = Find anything that matches the filetypes
            - {terms} = l = symbolic link
            - {terms} = f = files
            - {terms} = d = directory
        - [ -atime {terms} ] = Find anything that matches the access time
            - {terms} = +5 = accessed more than five days ago
        - [ -ctime {terms} ] = File anything that matches the creation time
            - {terms} = +5 = created than five days ago
        - [ -mtime {terms} ] = Find anything that matches the modification time
            - {terms} = +5 = modified more than five days ago
- Create archive from list of files
    - # ls | cpio -o > ../ls_archive.cpio
    - # find . -name "*.zip" | cpio -o > ../find_archive.cpio
- Unarchive a archive
    - # cpio -id < ..ls_archive.cpio
        - [ -id ] = unzip archive and create folder structure
- Create OR restore a image of a hard drive
    - # dd if={input} of={output}
        - {input} = /dev/sdb1 OR keydrive.img
        - {output} = keydrive.img OR /dev/sdb1
- Compress a file to .gz
    - # gzip {file}
    - Erases the original
- Uncompress a .gz file
    - # gunzip {file}
- Compress a file to .bz2
    - # bzip2 {file}
    - Erases the original
- Create OR decompress a archive
    - # tar {options} {filename} {sourcedirectory}
        - {filename} = filename including the extention
        - {sourcedirectory} = when creating a new archive the source directory needs to be put here
        - [ -cvf ] = Create a new archive, Verbose, Filename
        - [ -cvzf ] = Create a new archive, Verbose, Use gzip, Filename
        - [ -cvjf ] = Create a new archive, Verbose, Use bzip2, Filename
        - [ -xvf ] = Extract a archive, Verbose, Filename
        - [ -zxvf ] = Use gzip, Extract a archive, Verbose, Filename
        - [ -jxvf ] = Use bzip2, Extract a archive, Verbose, Filename

Video 21: Section 104.4 - Managing disk quotas

- Package needed for disk quotas: quota
- Quota`s are used on the entire drive
- Add usrquota and grpquota to the disk you want to use in the /etc/fstab file
- Activate quotas by unmounting and mouting the device, and use the # quotaoff {mountpoint}
- Create/check quota files
    - # quotacheck -cug {device}
        - {device} = /mnt/hard_drive/
- Edit quotas
    - # edquota {options} {username}
        - [ -u ] = edit a user`s quota file
        - [ -g ] = edit a group`s quota file
    - Edit the quotas of data AND inodes
        - Blocks = Used blocks, one block is 1000bytes
        - Soft = limit of  blocks
            - When passed, the user needs to get under the softlimit in 7 days else the user cannot use the drive anymore)
        - Hard = maximum limit of storage blocks used
            - When passed, write error/access denied
        - Inodes = Used inodes, number of files
        - Soft = limit of inodes
            - When passed, the user needs to get under the softlimit in 7 days else the user cannot use the drive anymore)
        - Hard = maximum limit of inodes used
            - When passed, write error/access denied
    - 0 = no limit
    - aquota.group and aquota.user are edited every time a user edits a file
- Get a report of the quota used on a drive
    - # repquota {device}
        - {device} = /mnt/hard_drive/

Video 22: Section 104.5 - Manage File Ownership and Permissions

- Change the owner of a file/folder
    - # chown {options} {newuser} FILE
        - {newuser} = the user that the new owner of the file is going to be
        - {newuser} = user:group OR user.group OR user OR :group can be used
        - [ -R ] = Change all the files in a folder (recursively)
- Change the owner group
    - # chgrp {newgroup} FILE
- Permissions (in # ls -l)
    - 1st character = Type of file (- file, d directory, l symbolic link)
    - 2,3,4 characters = Owner permissions READ, WRITE, EXECUTE
    - 5,6,7 characters = Group permissions READ, WRITE, EXECUTE
    - 8,9,10 characters = Others permissions READ, WRITE, EXECUTE
- Octal permissions
    - r = octal value of 4
    - w = octal value of 2
    - x = octal value of 1
    - RWX = 7 (4+2+1)
    - RW- = 6 (4+2)
    - R-X = 5 (4+1)
    - R-- = 4 (4)
    - --- = 0 (no permissions)
- Change file permissions
    - # chmod {permissons} FILE
        - {permissions} = 664 = Octal Permissions : RW- Owner, RW- Group, R-- Everybody
        - {permissions} = o-w = Remove write access from others
        - {permissions} = g-w = Remove write access from group
        - {permissions} = u-w = Remove write access from owner (user)
        - {permissions} = u=g = Make permissons from Owner and Group the same
- Change the standard permissions when a file is created
    - # umask
    - 777 - UMASK = standard permissions
    - New files do never have executable permissions
    - Change the umask in .profile so it is default on login
- Access Modes
    - SUID : 4 (set user id)
        - Executable runs with the permissions of the owner
        - # chmod u+s FILE (add SUID to a file)
        - # chmod 4733 FILE (SUID, RWX-WX-WX)
    - GUID : 2(set group id)
        - Executable runs with the permissions of the group
        - Any files/folders in a folder get the same group
        - # chmod g+s FILE (add GUID to a file or folder)
        - # chmod 2733 FILE (GUID, RWX-WX-WX)
    - Sticky bit : 1
        - Only the owner/root can delete the file/folder
        - Usefull in /tmp
        - # chmod o+t FILE (add Sticky Bit to a file or folder)
        - # chmod 1733 FILE (Sticky Bit, RWX-WX-WX)
    - Remove SUID, GUID, Sticky bit
        - # chmod 0733 FILE (RWX-WX-WX)
- Hardlink
    - Linking to the same Inode/
    - Cannot link across devices (has to be on the same drive)
- Softlink / Symbolic links
    - Points to a existing file
- Create a hardlink
    - # ln {sourcefile} {linkfile}
- Create a softlink
    - # ln -s {sourcefile} {linkfile}
- Show inodes in a directory
    - # ls -li

Video 24: Section 104.7 - Find system files, placing files in correct location}

- FHS (File Hirarchy Standard)
    - /
        - The root of the drive
    - /bin
        - Command binaries are stored here
    - /boot
        - The bootloader is stored here
    - /dev
        - Devices are stored here
    - /etc
        - Configuration files are stored here
    - /home
        - User home directories are stored here
    - /lib
        - Library files for executables are stored here
    - /proc
        - Virtual Filesystem
    - /root
        - Root user home directory
    - /sbin
        - System binaries
    - /tmp
        - Temporary file storage
    - /usr
        - User binaries, often ReadOnly
    - /var
        - Variable files, logs, mail
    - /media
        - Mount place for removable media
    - /mnt
        - Legacy location for removeable media (harddisks)
- Perform a filesearch in Real time
    - # find {searchlocation} {terms}
        - {terms} = -name "mail" = Search for files named the exact word mail
        - {searchlocation} = / = Start searching in the root directory
- Perform a filesearch from a database (updates once per 24h)
    - # locate {terms}
        - {terms} = "mail" = Search for files, which path have the word "mail"
    - Uses a database to search trough.
        - Manualy update the search database
            - # updatedb
        - Change locate settings
            - /etc/updatedb.conf
- Shows where a command is stored
    - # which {command}
- Shows if a command is using aliasses
    - # type {command}
- Shows where a command is stored and where the manual is
    - # whereis {command}