• RHEL supports seven types of files:
    • Regular
    • Directory
    • Block special device → Used by the OS to communicate with peripheral devices.
    • character special device → Used by the OS to communicate with peripheral devices.
    • symbolic link
    • named pipe → Used in IPC(Inter Process Communication)
    • socket → Used in IPC(Inter Process Communication)

Regular Files:

  • Regular files may contain text or binary data. These files may be shell scripts or commands in the binary form. When you list a directory, all line entries for files in the output that begin with the hyphen character (-) represent regular files.
    • Example: c2_1
    • The - before the rw permission depicts that it is a regular file.
  • file command: Returns the specific type of data that the file contains, in this case it’s ASCII text. c2_2
  • stat command: It simply states that the file is a regular file. c2_3

Directory Files:

  • Directories are logical containers that hold files and subdirectories.
  • The letter “d” at the beginning of each line entry identifies the file as a directory. c2_4
  • file command on /usr directory: c2_5
  • stat command on /usr directory: c2_6

Block and character special device files:

  • What are Device files? Each piece of hardware in the system has an associated file in the /dev directory that is used by the system to communicate with that device. This type of file is called a device file.
  • Types of device files:
    • Block → On the initial with the letter b we can distinguish it’s Block device file. c2_7
    • Character/ raw → On the initial with the letter c we can distinguish it’s character device file. c2_8
  • file command on both of the directories → /dev/console and /dev/nvme0n* c2_9
  • stat command on both of the directories → /dev/console and /dev/nvme0n* c2_10 c2_11

Concept of major number:

c2_12 Let’s elaborate the picture

  • Every hardware device such as a disk, CD/DVD, printer, and terminal has an associated device driver loaded in the kernel. The kernel communicates with hardware devices through their respective device drivers. Each device driver is assigned a unique number called the major number, which the kernel uses to recognize its type.

Concept of Minor number:

c2_13

  • There may be more than one instance of the same device type in the system. In that case, the same driver is used to control all those instances. For example, ==SATA device driver controls all SATA hard disks and CD/DVD drives==. The kernel in this situation allots a minor number to each individual device within that device driver category to identify it as a unique device. This scheme applies to disk partitions as well. In short, a major number points to the device driver, and a minor number points to a unique device or partition that the device driver controls.

Practical example of major and minor numbers:

  • Previously when we used the file command and ls -l on /dev/console and /dev/nvme0n* directories, we will analyze them again and identify where actually it shows the major and minor numbers:
    • ls -l output analyze: c2_14
      • The major number 5 is for character device files and it is reserved for tty and console related devices.
        • /dev/tty - (5,0)
        • /dev/console - (5,1)
        • /dev/ptmx - (5,2)
      • The major number 259 represents Block extended device files and it is dynamically assigned to NVME devices.

EXTRA MAJOR NUMBERS(for knowledge):

  1. Major number 8 represents the block device driver for SATA disks.
  2. Major number 253 denotes the driver for device mapper.
  3. Major number 11 represents optical devices.

Symbolic links/ soft link/ symlink:

  • It is considered a shortcut to another file or directory.
  • When we will perform ls -l/ longlisting of files/directories, the initial letter will be l for a symlink plus an arrow will be pointing to the target link.
    • c2_15
  • file and stat command for additional information:
    • c2_16

Compression and archiving:

  • What is compression?
    • It is the process of grouping multiple files and then compress them together to save space.
  • What is archiving?
    • They contain single file that further contains one or more compressed/uncompressed files along with metadata like folder structures.
    • The archiving technique mostly used for long-term backups and storages etc.

Using gzip and gunzip:

  • The gzip command is used to create a compressed file of each of the specified files and it adds the .gz extension to each file for identification.
    • We will compress and decompress the file fstab
      • First copy the file from /etc/fstab to the current working directory c2_17 - Now use the gzip command to compress the file → c2_18 - Check more info about the compressed file using the following command:
      • gzip -l fstab.gz
        
      • c2_19
      • Decompress the file using the command gunzipc2_20

Using bzip2 and bunzip2:

  • They are same as gzip and gunzip . Instead bzip2 compress a file with the extension .bz2
    • bzip2 : c2_21
    • bunzip2 : c2_22

Using tar:

  • The tar (tape archive) command is used to create, append, update, list, and extract files or an entire directory tree to and from a single file, which is called a tarball or tarfile. This command can be instructed to also compress the tarball after it has been created. Commands:
  1. To create a tarball called /tmp/home.tar of the entire /home directory, use the -v option for verbosity and the -f option to specify the name of the archive file with the command, -c creates a tarball.
tar -cvf /tmp/home.tar /home

c2_23 2. To create a tarball of selected files:

tar -cvf /tmp/files.tar /etc/passwd /etc/yum.conf

c2_24 3. To append files located in the /etc/yum.repos.d directory to the existing tarball /tmp/files.tar:

tar -rvf /tmp/files.tar /etc/yum.repos.d

c2_25 4. To list what files are included in the files.tar tarball:

tar -tvf /tmp/files.tar

c2_26 5. To extract the files from the tarball

tar -xf /tmp/files.tar
  1. tar also supports options to directly compress the target file while being archived using the gzip or bzip2 command:
optionDescription
-jCompress a tarball with bzip2
-zCompresses a tarball with gzip
Note

Archiving and compression are tasks usually done together to produce smaller archive files.