This post does not intend to provide comprehensive information on how to pass the certification, but serves as study notes on better understanding Linux system.

Common File Types: RHEL supports seven types of files: regular, directory, block special device, character special device, symbolic link, named pipe, and socket.

Linux does not require file extension, though it’s still a good idea to add the extension for readiability. To identify the file type of a file, the command file and stat can be used:

file file.tar

file.tar: POSIX tar archive (GNU)

stat file.tar

  File: file.tar
  Size: 10240           Blocks: 24         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 36200       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-08-04 09:10:58.184019228 -0400
Modify: 2020-08-04 09:10:53.528028127 -0400
Change: 2020-08-04 09:10:53.528028127 -0400
 Birth: -

Archieve and compress files

Sometimes files need to be backup to a remote location. Archive files into a single file will save a huge amount of time on network transaction since instead of generating a session for each file, only one session is needed.

To archieve a file:

tar -cvf file.tar file1 file2

List the content of an archieve:

tar -tvf file.tar

-rw-r--r-- root/root         0 2020-08-04 09:10 file1
-rw-r--r-- root/root         0 2020-08-04 09:10 file2

Extract the archieve:

tar -xvf file.tar


Compress files can reduce the file size. The effect of compression is apparant on sequential data than random data.

gzip -k file1 #compress with gzip, -k flag keeps the source files

bzip2 -k file1 #compress with bzip2, -k flag keeps the source files

Extract a file:

gunzip file1.gz #extract gzip

bunzip2 file1.bz2 #extract bzip2

Compress directory or multiple files:

tar -jcvf file.bz2 file1 file2 # archive and compress file1 and file2 with bzip2

tar -zcvf file.gz file1 file2 # archive and compress file1 and file2 with gzip

Extract the archive and compress file:

tar -jxvf file.bz2 file1 file2 # extract tar and bzip2

tar -zxvf file.gz file1 file2 # extract tar and gzip


File Linking

Before going into file linking the concept of inode is important. An Inode is a unique number assigned to files and directories by the kernal for tracking and managing purposes.

View the inode of file or directory

li -li #the -i flag provide that inode

 36197 drwxr-xr-x 2 root root 4096 Aug  4 09:41 e02

In this case the inode 36197 is assigned to the ’e02’ directory.

Hard Link: sharing the same inode number, cannot be used to link directories

To create a hard link(file3) for file2:

ln file2 file3

36199 -rw-r--r-- 2 root root 0 Aug  4 09:56 file2
36199 -rw-r--r-- 2 root root 0 Aug  4 09:56 file3

Soft Link: sharing different inode number, akin to shortcuts in Windows

To create a soft link(file4) for file3:

ln -s file3 file4

36199 -rw-r--r-- 2 root root 0 Aug  4 09:56 file3
36200 lrwxrwxrwx 1 root root 5 Aug  4 09:59 file4 -> file3

Notice that the inode is different for file4.