Module i Sample Notes
Module i Sample Notes
Module I
The Kernel
System Library
Hardware layer
System
Shell utility.
1. Kernel:
2. System Libraries
4. Hardware layer
5. Shell
It can take commands through the user and runs the functions of
the kernel.
1. pen Source
2. Security
The Linux security feature is the main reason that it is the most favorable option
for developers. It is not completely safe, but it is less vulnerable than others.
Each application needs to authorize by the admin user. The virus is not executed
until the administrator provides the access password. Linux systems do not
require any antivirus program.
3. Free
Certainly, the biggest advantage of the Linux system is that it is free to use. We
can easily download it, and there is no need to buy the license for it. It is
distributed under GNU GPL (General Public License). Comparatively, we have
to pay a huge amount for the license of the other operating systems.
4. Lightweight
Linux is lightweight. The requirements for running Linux are much less than
other operating systems. In Linux, the memory footprint and disk space are also
lower. Generally, most of the Linux distributions required as little as 128MB of
RAM around the same amount for disk space.
5. Stability
Linux is more stable than other operating systems. Linux does not require to
reboot the system to maintain performance levels. It rarely hangs up or slow
down. It has big up-times.
6. Performance
7. Flexibility
Linux operating system is very flexible. It can be used for desktop applications,
embedded systems, and server applications too. It also provides various
restriction options for specific computers. We can install only necessary
components for a system.
8. Software Updates
In Linux, the software updates are in user control. We can select the required
updates. There a large number of system updates are available. These updates
are much faster than other operating systems. So, the system updates can be
installed easily without facing any issue.
9. Distributions/ Distros
There are many Linux distributions available in the market. It provides various
options and flavors of Linux to the users. We can choose any distros according
to our needs. Some popular distros are Ubuntu, Fedora, Debian, Linux Mint,
Arch Linux, and many more.
For the beginners, Ubuntu and Linux Mint would be useful and, Debian and
Fedora would be good choices for proficient programmers.
Almost all Linux distributions have a Live CD/USB option. It allows us to try
or run the Linux operating system without installing it.
It supports almost all of the most used programming languages such as C/C+
+, Java, Python, Ruby, and more. Further, it offers a vast range of useful
applications for development.
The programmers prefer the Linux terminal over the Windows command line.
The package manager on Linux system helps programmers to understand how
things are done. Bash scripting is also a functional feature for the programmers.
It also provides support for SSH, which helps in managing the servers quickly.
Linux provides large community support. We can find support from various
sources. There are many forums available on the web to assist users. Further,
developers from the various opensource communities are ready to help us.
14. Privacy
Linux always takes care of user privacy as it never takes much private data from
the user. Comparatively, other operating systems ask for the user's private data.
15. Networking
16. Compatibility
Linux is compatible with a large number of file formats as it supports almost all
file formats.
17. Installation
Linux installation process takes less time than other operating systems such as
Windows. Further, its installation process is much easy as it requires less user
input. It does not require much more system configuration even it can be easily
installed on old machines having less configuration.
Linux system provides multiple desktop environment support for its enhanced
use. The desktop environment option can be selected during installation. We
can select any desktop environment such as GNOME (GNU Network Object
Model Environment) or KDE (K Desktop Environment) as both have their
specific environment.
19. Multitasking
7. For some purpose, init starts a method permitting you to log in, typically at
the top or close to the top of the boot sequence.
KERNAL
The Linux® kernel is the main component of a Linux operating
system (OS) and is the core interface between a computer’s
hardware and its processes. It communicates between the 2,
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.
What the kernel does
The kernel has 4 jobs:
1. Memory management: Keep track of how much memory is used to store what, and where
2. Process management: Determine which processes can use the central processing unit
(CPU), when, and for how long
3. Device drivers: Act as mediator/interpreter between the hardware and processes
4. System calls and security: Receive requests for service from the processes
The kernel, if implemented properly, is invisible to the user, working in its own little
world known as kernel space, where it allocates memory and keeps track of where
everything is stored. What the user sees—like web browsers and files—are known
as the user space. These applications interact with the kernel through a system call
interface (SCI).
Think about it like this: The kernel is a busy personal assistant for a powerful
executive (the hardware). It’s the assistant’s job to relay messages and requests
(processes) from employees and the public (users) to the executive, to remember
what is stored where (memory), and to determine who has access to the executive at
any given time and for how long.
Experience Red Hat Enterprise Linux
1. The hardware: The physical machine—the bottom or base of the system, made up of
memory (RAM) and the processor or central processing unit (CPU), as well as input/output
(I/O) devices such as storage, networking, and graphics. The CPU performs computations
and reads from, and writes to, memory.
2. The Linux kernel: The core of the OS. (See? It’s right in the middle.) It’s software residing in
memory that tells the CPU what to do.
3. User processes: These are the running programs that the kernel manages. User processes
are what collectively make up user space. User processes are also known as just processes.
The kernel also allows these processes and servers to communicate with each other (known
as inter-process communication, or IPC).
Code executed by the system runs on CPUs in 1 of 2 modes: kernel mode or user
mode. Code running in the kernel mode has unrestricted access to the hardware,
while user mode restricts access to the CPU and memory to the SCI. A similar
separation exists for memory (kernel space and user space). These 2 small details
form the base for some complicated operations like privilege separation
for security, building containers, and virtual machines.
Local Variable
A local variable is a special type of variable which has its scope only
within a specific function or block of code. Local variables can override the
same variable name in the larger scope.
Global Variables
A global variable is a variable with global scope. It is accessible
throughout the program. Global variables are declared outside any block
of code or function.
Shell Variables
These are special types of variables. They are created and maintained by
Linux Shell itself. These variables are required by the shell to function
properly They are defined in Capital letters and to see all of them, we can
use set / env / printenv command
Some useful shell variables are –
The general-purpose computer system needs to store data systematically so that we can
easily access the files in less time. It stores the data on hard disks (HDD) or some
equivalent storage type. There may be below reasons for maintaining the file system:
o Primarily the computer saves data to the RAM storage; it may lose the data if it gets
turned off. However, there is non-volatile RAM (Flash RAM and SSD) that is
available to maintain the data after the power interruption.
o Data storage is preferred on hard drives as compared to standard RAM as RAM
costs more than disk space. The hard disks costs are dropping gradually
comparatively the RAM.
The Linux file system contains the following sections:
If we have an unsupported file format in our file system, we can download software to
deal with it.
A file system is designed in a way so that it can manage and provide space for non-
volatile storage data. All file systems required a namespace that is a naming and
organizational methodology. The namespace defines the naming process, length of the
file name, or a subset of characters that can be used for the file name. It also defines the
logical structure of files on a memory segment, such as the use of directories for
organizing the specific files. Once a namespace is described, a Metadata description
must be defined for that particular file.
The data structure needs to support a hierarchical directory structure; this structure is
used to describe the available and used disk space for a particular block. It also has the
other details about the files such as file size, date & time of creation, update, and last
modified.
Also, it stores advanced information about the section of the disk, such as partitions and
volumes.
The advanced data and the structures that it represents contain the information about
the file system stored on the drive; it is distinct and independent of the file system
metadata.
Advertisement
Linux file system contains two-part file system software implementation architecture.
Consider the below image:
The file system requires an API (Application programming interface) to access the
function calls to interact with file system components like files and
directories. API facilitates tasks such as creating, deleting, and copying the files. It
facilitates an algorithm that defines the arrangement of files on a file system.
The first two parts of the given file system together called a Linux virtual file system. It
provides a single set of commands for the kernel and developers to access the file
system. This virtual file system requires the specific system driver to give an interface to
the file system.
Directory Structure
The directories help us to store the files and locate them when we need them. Also,
directories are called folders as they can be assumed of as folders where files reside in
the form of a physical desktop analogy. Directories can be organized in a tree-like
hierarchy in Linux and several other operating systems.
The directory structure of Linux is well-documented and defined in the Linux FHS
(Filesystem Hierarchy Standard). Referencing those directories if accessing them is
achieved via the sequentially deeper names of the directory linked by '/' forward slash
like /var/spool/mail and /var/log. These are known as paths.
The below table gives a very short standard, defined, and well-known top-level Linux
directory list and their purposes:
o / (root filesystem): It is the top-level filesystem directory. It must include every file
needed to boot the Linux system before another filesystem is mounted. Every other
filesystem is mounted on a well-defined and standard mount point because of the
root filesystem directories after the system is started.
o /boot: It includes the static kernel and bootloader configuration and executable files
needed to start a Linux computer.
o /bin: This directory includes user executable files.
o /dev: It includes the device file for all hardware devices connected to the system.
These aren't device drivers; instead, they are files that indicate all devices on the
system and provide access to these devices.
o /etc: It includes the local system configuration files for the host system.
o /lib: It includes shared library files that are needed to start the system.
o /home: The home directory storage is available for user files. All users have a
subdirectory inside /home.
o /mnt: It is a temporary mount point for basic filesystems that can be used at the time
when the administrator is working or repairing a filesystem.
o /media: A place for mounting external removable media devices like USB thumb
drives that might be linked to the host.
o /opt: It contains optional files like vendor supplied application programs that must be
placed here.
o /root: It's the home directory for a root user. Keep in mind that it's not the '/' (root) file
system.
o /tmp: It is a temporary directory used by the OS and several programs for storing
temporary files. Also, users may temporarily store files here. Remember that files
may be removed without prior notice at any time in this directory.
o /sbin: These are system binary files. They are executables utilized for system
administration.
o /usr: They are read-only and shareable files, including executable libraries and
binaries, man files, and several documentation types.
o /var: Here, variable data files are saved. It can contain things such as MySQL, log
files, other database files, email inboxes, web server data files, and much more.
Advertisement
o Specifying paths: Linux does not use the backslash (\) to separate the components;
it uses forward slash (/) as an alternative. For example, as in Windows, the data may
be stored in C:\ My Documents\ Work, whereas, in Linux, it would be stored in /home/
My Document/ Work.
o Partition, Directories, and Drives: Linux does not use drive letters to organize the
drive as Windows does. In Linux, we cannot tell whether we are addressing a
partition, a network device, or an "ordinary" directory and a Drive.
o Case Sensitivity: Linux file system is case sensitive. It distinguishes between
lowercase and uppercase file names. Such as, there is a difference between test.txt
and Test.txt in Linux. This rule is also applied for directories and Linux commands.
o File Extensions: In Linux, a file may have the extension '.txt,' but it is not necessary
that a file should have a file extension. While working with Shell, it creates some
problems for the beginners to differentiate between files and directories. If we use the
graphical file manager, it symbolizes the files and folders.
o Hidden files: Linux distinguishes between standard files and hidden files, mostly the
configuration files are hidden in Linux OS. Usually, we don't need to access or read
the hidden files. The hidden files in Linux are represented by a dot (.) before the file
name (e.g., .ignore). To access the files, we need to change the view in the file
manager or need to use a specific command in the shell.
‘cal -y’: Shows the calendar of the complete current year with
the current date highlighted.
‘cal [year]’: Shows the whole calendar of the year. For example,
‘cal 2018‘ displays the calendar for the year 2018.
‘cal -j’: Shows the calendar of the current month in the Julian
calendar format not in the default Gregorian calendar format.
In Julian calendar format, the date does not reset to 1 after every
month’s end i.e. after 31st Jan, Feb will start as 32nd Feb, not as
1st Feb. But in the Gregorian calendar format, the date is reset to
1 after every month’s end i.e after 31st Jan, Feb will start as of 1st
Feb.
ntroduction
The "date" command in Linux is a simple but powerful tool used to display
the current date and time, as well as set the system date and time. This
command is extremely useful for troubleshooting and system administration
tasks, and is a vital tool in understanding any Linux user. In this article, we'll
discuss the basic usage of the date command, as well as some of its more
advanced options and features. We'll also cover some examples of how the
date command can be used in real-world scenarios.
$ date
Tue Jan 25 14:20:34 EST 2022
Formatting the Output
One of the most useful features of the date command is the ability to specify
a particular format for date and time output. This can be done using the "+"
option followed by a format specifier. For example, to display the date in the
"YYYY-MM-DD" format, use the command −
$ date +%F
2022-01-25
There are many format specifiers that can be used with the date command,
each of which will display the date and time in a different format. Some of
the more commonly used format specifiers include −
%Y − displays the year with century as a decimal number
%m − displays the month as a decimal number (01-12)
%d − displays the day of the month as a decimal number (01-31)
%H − displays the hour (24-hour clock) as a decimal number (00-23)
%M − displays the minute as a decimal number (00-59)
%S − displays the second as a decimal number (00-59)
Setting the Date and Time
The date command can also be used to set the system date and time. To do
this, you need to log in as the root user. Use the following command to set
the date and time.
$ sudo date -s "25 JAN 2022 14:20:34"
You can also set the date and time with the "-u" option to set it to
Coordinated Universal Time (UTC) instead of local time.
$ sudo date -us "25 JAN 2022 14:20:34"
Linux Directory Commands
1. pwd Command
The pwd command is used to display the location of the current working directory.
Syntax:
1. pwd
Output:
2. mkdir Command
Advertisement
The mkdir command is used to create a new directory under any directory.
Syntax:
3. rmdir Command
Syntax:
4. ls Command
Syntax:
Advertisement
1. ls
Output:
5. cd Command
Advertisement
Syntax:
1. cd <directory name>
Output:
The touch command is used to create empty files. We can create multiple empty files by
executing it once.
Syntax:
7. cat Command
The cat command is a multi-purpose utility in the Linux system. It can be used to create
a file, display content of the file, copy the content of one file to another file, and more.
Syntax:
Advertisement
8. rm Command
Syntax:
rm <file name>
Output:
9. cp Command
Syntax:
Output:
10. mv Command
The mv command is used to move a file or a directory form one location to another
location.
Syntax:
The rename command is used to rename files. It is useful for renaming a large group of
files.
Syntax:
cat jayesh.txt
Note: `ls` command is used to display all files and directories in the
current location.
2. How to View the Content of Multiple Files in Linux
Syntax:
cat file_name1 file_name2
Example: If we have two files , file1 and file2.
cat file1 file2
cat -n file_name
Example: If our file_name is file2.
cat -n file2
cat -n file2
Here, the cat command, used with the redirection ( >), allows you to create
a new file named “jayesh1” and input content directly into it. The
subsequent ls command lists all files in the current location.
4. How to Create a file and add content in Linux Using `cat` Command
If you want to create a new file or overwrite an existing file with new
content, you can use ‘cat’ with the output redirection (` >`):
Syntax:
cat > newfile_name
Example: If we want to create a newfile_name = jayesh1.
cat > jayesh1
ls
This will allow you to type text directly into the terminal, and when you
press Ctrl + D, the entered text will be saved to new_file.txt.
`ls` command is used to display all files and directories in the current
location.
tac file2
This will display the content of ‘jayesh1’ with a ‘$’ character at the end of
each line, indicating the line’s terminate.
10. `-A` Command Line Option in `cat` Command in Linux
The ‘-A’ option allows you to combine the effects of ‘-v’, ‘-E’, and ‘-T’
options. Instead of writing ‘-vET’ in the command, you can use ‘-A’:
Syntax:
cat -A "filename"
Explanation:
The -v option creates non-printing characters visible (except for tabs
and line breaks).
The -E option emphasizes the end of each line with a $.
The -T option shows tabs as ^I.
This will display the content of ‘filename’ with non-printing characters
visible, line endings highlighted, and tabs displayed as ‘^I’.
11. How to Open Dashed Files in Linux Using `cat` Command
To open a file with a dash at the beginning of its name, use the ‘–‘ option:
Syntax:
cat -- "-dashfile"
Example:
cat -- "-jayesh2"
Output:
Will show that much content, which could fit in terminal and
will ask to show more.
13. Merge Contents of Multiple Files Using `cat` Command
To merge the contents of multiple files into a single file, use the redirection
(‘>’)
Syntax:
cat "filename1" "filename2" "filename3" > "merged_filename"
Example:
cat "file1" "file2" "file3" > "merged123"
This will concatenate the contents of “file1” “file2” “file3” into “merged123”.
14. Display Content of All Text Files in a Folder Using `Cat` Command
To display the content of all text files in a folder, use the wildcard (‘*.txt’):
Syntax:
cat *.txt
Will show the content of all text files present in the folder.
15. Cat Command to Append to an Existing File:
To append text to an existing file, use the ‘>>’ operator along with ‘cat’:
Syntax:
cat >> geeks.txt
The newly added text.
This will append the text “The newly added text.” to the end of the
‘geeks.txt’ file.