3.0 Introduction to Red Hat Linux Key file system
Welcome back, in this ‘RHCSA examination preparation guide’ series two articles are published, this is third part of the series in continuation, in previous two articles we understood basics of Red Hat Enterprise Linux including Installation, system registration to Red Hat network, then we learned few Linux basic commands, what is bash, what is Linux terminal. Let us move ahead, as we know that everything in Linux is a file, all of the configurations settings, drivers software etc. everything is stored in Linux as editable text file, therefore to govern Linux System it is must for Linux user or administrator to understand key files which act as skeleton of the system, every file or directory in Linux architecture is designated to play some unique and important role, such files/directories are called system default files/directories. Any defect in these configuration files or some unauthorized access to the files can give some serious damage to the system, some important key files and directories are common for all of Linux distributions.
3.1 Understanding Linux file system hierarchy
Slash is known as the root directory, rest of the files and directories resides under root (/), this is like the root of a tree where rest of the files/directories are like branches of that root. Important to note there is no need to memorize all of the directories, you just need to understand only a few directories which are important from RHCSA exam preparation point of view have a look.
$ cd /
$ ls
Let us discuss every file system step by step
- /boot:/boot is a dedicated separate partition on hard disk. It stores Linux kernel and related files, initramfs and grub (boot loader). After BIOS process is handed over to /boot to boot the system, it contains kernel configuration options. Config-x-x-x It is a text file that contains kernel configuration options, have a look in that file. Give ‘uname -r’ command:
See the input, it will display kernel version installed. It has same extension as of config-x.x.x file. Initramfs It provides drives appropriately to find the root system, if you rename or remove that file your system will get the boot failure, so never tease /boot files. VM Linux It is the kernel itself. In a nutshell /boot contains all of the files which are required for boot process.
2. /usr: directory can be called software directory as in includes all installed software, shared libraries, user commands, directories which come under /usr are as follows:
2.1 /usr/local- Locally customized software goes under this directory.
2.2 /usr/bin- All of the command scripts resides under that directory.
2.3 /usr/local– All of the Administration related commands available under this directory.
3. /etc- All of the configuration files are stored in /etc/, all of servers or services which you will configure, have their editable configuration files stored under /etc.
4. /home- This is the directory where user stores all of their data, and configuration files, every user have their separated sub-directory under /home.
5. /tmp- This directory is also known as a temporary directory, where all of the temporary data is stored, it can be accessed equally by root and ordinary users.
6. /var- contains files that may change in size dynamically, like log files, spool or mail files.
7. /dev- contains files that is required by the system to interact with the hardware, these directories are mandatory for booting the system.
8. /proc- this file system provides access to kernel, cpu, memory related information can retrieve from that directory.
9. /media- By default optical or usb devices are mounted in that directory.
10. /lib, /lib64- Shared libraries that are utilized in /boot, /sbin and bin.
3.2 Essential Linux file management tasks
3.2.1 Absolutes paths and relative path
By default a user login to his home directory, when a user needs to handle certain xyz file or directory across the system, it is required to define the path of that xyz directory. Now, path of this particular directory can be defined by two methods, the first option is that user start defining address of xyz directory Starting from very top location i.e. from slash and move down step by step to desired location of xyz, that is known as absolute path, absolute path will always begin with / (slash). Let us assume that we are logged in as user1 user, and wants to go to user2 directory, which is the home directory of another user, have a glimpse of below diagram.
Top parent directory is / under which home directory exist and further under this home directory user2 directory exists which is over final destination. Let us type this path step by step:
$ cd /home/user2
Let us assume another scenario to understand relative path, we have discussed how we moved from top to down in absolute path scenario. However, when you navigate from your current location directly to xyz destination directly, then you follow relative path. The relative path will never start with slash(/) in any circumstances. Consider below diagram:
Let us move from user1 directory to user2 directory, we can see that both user1 and user2 are under /home directory, to switch from user1 to user2, move from user1 to /home(a step up), now move from /home to user2 (a step down). To move a step up from current location use following command.
$cd ../user2
Assume user was in his home directory (/home/user1) after above command you will move a step above (/home), now you can go down to user2 which is under /home (/home/user2).
3.2.2 Managing files with use of command line tools
In this file management section, we will discuss how to – create directories and files, how to remove them, how to move them from one place to another and how to rename or copy any file or directory.
- mkdir – create a directory.
Syntex: $mkdir <directory_name>
$ mkdir example
User ls command to have a look
Create two directories with a single command
To create directories along with parent directory.
$ mkdir -p rajneesh/um1 rajneesh/um2 rajneesh/um3
-p option will create parent directory first, under this parent directory all three (um1, um2, um3) directories will be created, total 4 directories will be created.
2. rmdir- to remove a directory.
Syntex: $rmdir <directory_name>
But, important to note that with rmdir you can remove only empty directories, let us try to remove entire ‘rajneesh’ directory which possesses um2 and um3 subdirectories.
3. rm – To remove files or the directories which are not empty, use -r option for recursive mode.
4. cp – to copy one file to another file, contents will be overwrite, or one file to another directory.
Syntex: $ cp file1 file2
In below example we created two different files with different contents, then copy file 1 to file 2 and see contents of file 2.
You can also copy one directory to another directory if directory is not empty use ‘-r’ option, let us assume following example, create raj and ra1 directories, create a file in raj, now copy raj directory to raj1,
$ mkdir raj raj1 $ cd raj $ touch file1 $ cd .. $ cp -r raj raj1
Have a look of raj1 directory, contents of raj are present in raj1.
5. mv- To move one source (file or directory) to some destination.
syntex : $ mv source destination
The difference between copy and move is that when you copy something the original source will remain there, but when you mv something, the original source will be removed automatically. In below example you can notice that only destination directory is present after mv command.
6. touch: used to create empty files.
Syntex: $ touch file1 file2
Create multiple files
$ touch file1 file2 file3 file4
Or you can create files in bulk, put a range in curly braces spaced by .., close the braces and add the file extension type as shown below.
$ touch {1..100}.txt
3.3 Conclusion
This was the third chapter of RHCSA preparation series, by the end of this chapter user will be able to understand the relative path and absolute path, few important key directories and their role, a user can remove, move or create files and directories. Is is recommended that user must practice all of the mentioned commands, use help manuals available on the internet. Although we are trying to include maximum of the mandatory part required to RHCSA preparation but still few things will get skipped, you can inform in that case.
3.4 DIY Practice for RHCSA Examination
On the basis of this chapter user is expected to perform following practicals:
- Create two named example1 and example2, crate cert1 under example1, and cert2 under example2, further, create test1 directory under cert2. Now move to test directory using an absolute path, then go to example1 from test using a relative path.
2. Create 100 files with a single command having .mp3 extension.
3. Remove entire exampl2 directory and subdirectories with a single command.
3.5 Things we will include in next RHCSA tutorial
In next chapter we will understand the use “file globbing” or “global commands”, getting help using man pages, help commands, and detailed understanding of text file editing with vim editor, file redirection etc. Have fun!!