Linux Architecture :
1. Hardware Layer:- Linux operating system contains a hardware layer that consists of several peripheral devices like CPU, HDD & RAM.
2. Kernel:- The Linux kernel is the main component of a Linux operating system and is the core interface between a computer’s hardware and its processes. It communicates between the two, managing resources as efficiently as possible.
The kernel is so named because, like a seed inside a hard shell, it exists within the OS and controls all the major functions of the hardware, whether it’s a phone, laptop, server, or any other kind of computer.
3. Shell:- It is an interface between the kernel and the user. It can afford the services of kernel. It can take commands through the user and runs the functions of the kernel.
4. Application Layer:- This is the topmost layer of the Linux architecture and consists of the various applications that run on the operating system. These can be anything from productivity software and games to web browsers and media players.
Linux File System Hierarchy :
In Linux everything is represented as a file including a hardware program, the files are stored in a directory and every directory contains a file with a tree structure. That is called File System Hierarchy.
Linux uses a single-rooted, inverted tree-like structure.
Root Directory represents with "/". It is a top-level directory in Linux.
/root - The root filesystem is the top-level directory of the filesystem. It must contain all of the files required to boot the Linux system before other filesystems are mounted.
/bin - The /bin directory contains user executable files.
/boot - Contains the static bootloader and kernel executable and configuration files required to boot a Linux computer.
/dev - It contains hardware device files which include terminal devices, USB, or any device attached to the system.
/etc - It contains all configuration files of the server.
/home - It is the directory where user home directories are stored in Linux, allowing each user to store their files and data in a private location.
/var - The variable data files such as log files are located in the /var directory.
/mnt - /mnt is a directory used as a temporary mount point for external file systems or devices, such as USB drives or network shares.
/usr - These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.
File permissions :
The first character, "d", indicates that it is a directory. The remaining nine characters are grouped into three sets of three characters, where each set represents the permissions for the user, group and others in that order.
Each set consists of three characters: "r" for read permission, "w" for write permission, and "x" for execute permission. If permission is granted, the corresponding character is present; otherwise, a "-" is present instead.
0 represents ---, 1 represents --x and so on like three digits binary number. Eg:- 101 will be equivalent to r-x and 101 in decimal is 5. Eg 2:- drwxr-xr-- will be equivalent to 754 where 7 is for rwx, 5 for r-x & 4 for r--
User & Group :
A user is an account used by an individual to log in and interact with the system. A user can have a home directory, which is a private space on the file system where the user can store files and customize their environment. Each user is identified by a unique username and has a unique user ID (UID).
A group, on the other hand, is a collection of users who share certain permissions or access to resources on the system. By default, every user in Linux belongs to at least one group, which is identified by a unique group ID (GID). Groups are used to simplify file permissions and manage access to shared resources.
Adding a user :-
(Here bob is the initial user)
sudo useradd <username>
Example:- sudo useradd devops
To check users detail : sudo cat /etc/passwd
Adding a Group :-
sudo groupadd <groupname>
Example:- sudo groupadd batch-eng
To check group details : sudo cat /etc/group
Adding a user in a Group :-
Adding single user:- sudo gpasswd -a <username> <groupname>
Example: sudo gpasswd -a devops batch-eng
Adding multiple users:- sudo gpasswd -M <username1>, <username2> <groupname>
Example: sudo gpasswd -M devops, john batch-eng
Deleting a user :-
sudo userdel <username>
Example : sudo userdel devops
That's it! The user "devops" is now removed from the system. Note that any files or directories owned by the user will still exist on the system, but will be owned by the root user.
If you want to remove the user's home directory and all of its contents, use the -r
option with the userdel
command.
-> sudo userdel -r devops
Deleting a group :-
sudo groupdel <groupname>
Example : sudo groupdel batch-eng
To check if group is deleted type :
-> getent group <groupname>
If it is deleted it will return no output else check /etc/group
Changing group of a file:-
myfile.txt has a group bob
To change its group to batch-eng, type:
sudo chgrp batch-eng myfile.txt
awk command :
Syntax: awk 'query' filename
We use
->sudo journalctl -q
to view log messages from the system journal.
Now, awk
is a versatile command-line tool used for processing text files and generating reports.
So to find the 4th & 5th column of second row, we type:
->sudo journalctl -q | awk 'NR==2 {print $4,$5}'