Linux Unit I
Linux Unit I
Linux Unit I
UNIT 1
WHAT IS LINUX OS :
Linux is an open-source operating system like other operating systems such as Microsoft
Windows, Apple Mac OS, iOS, Google android, etc. An operating system is a software that
enables communication between computer hardware and software. It conveys input to get
processed by the processor and brings output to the hardware to display it. This is the basic
function of an operating system. Although it performs many other important tasks, let's not
talk about that.
Linux is around us since the mid-90s. It can be used from wristwatches to supercomputers. It
is everywhere in our phones, laptops, PCs, cars, and even in refrigerators. It is very much
famous among developers and normal computer users.
Linux kernel is the core part of the operating system. It establishes communication between
devices and software. Moreover, it manages system resources. It has four responsibilities:
● device management: A system has many devices connected to it like CPU, a memory
device, sound cards, graphic cards, etc. A kernel stores all the data related to all the
devices in the device driver (without this kernel won't be able to control the devices).
Thus kernel knows what a device can do and how to manipulate it to bring out the
best performance. It also manages communication between all the devices. The kernel
has certain rules that have to be followed by all the devices.
● Memory management: Another function that kernel has to manage is the memory
management. The kernel keeps track of used and unused memory and makes sure that
processes shouldn't manipulate data of each other using virtual memory addresses.
● Process management: In the process, management kernel assigns enough time and
gives priorities to processes before handling CPU to other processes. It also deals with
security and ownership information.
● Handling system calls: Handling system calls means a programmer can write a query
or ask the kernel to perform a task.
2) System Libraries
System libraries are special programs that help in accessing the kernel's features. A kernel has
to be triggered to perform a task, and this triggering is done by the applications. But
applications must know how to place a system call because each kernel has a different set of
system calls. Programmers have developed a standard library of procedures to communicate
with the kernel. Each operating system supports these standards, and then these are
transferred to system calls for that operating system.
The most well-known system library for Linux is Glibc (GNU C library).
3) System Tools
Linux OS has a set of utility tools, which are usually simple commands. It is a software
which GNU project has written and publish under their open source license so that software
is freely available to everyone.
With the help of commands, you can access your files, edit and manipulate data in your
directories or files, change the location of files, or anything.
4) Development Tools
With the above three components, your OS is running and working. But to update your
system, you have additional tools and libraries. These additional tools and libraries are
written by the programmers and are called tool chain. A tool chain is a vital development tool
used by the developers to produce a working application.
These end tools make a system unique for a user. End tools are not required for the operating
system but are necessary for a user.
Some examples of end tools are graphic design tools, office suites, browsers, multimedia
players, etc.
Advantages of Linux
Linux is an open-source operating system like Windows and MacOS. It is not just limited to
the operating system, but nowadays, it is also used as a platform to run desktops, servers, and
embedded systems. It provides various distributions and variations as it is open source and
has a modular design. The kernel is a core part of the Linux system.
Linux system is used to manage various services such as process scheduling, application
scheduling, basic peripheral devices, file system, and more. Linux provides various
advantages over other operating systems such as Windows and macOS. So, it is used in
almost every field, from cars to home appliances and smartphones to servers
(supercomputers).
In this section, we will see some major advantages of the Linux system. Further, we will see
the advantages of Linux over other operating systems and will determine why it is better than
other operating systems.
1. pen Source
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 a 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 rebooting the
system to maintain performance levels. It rarely hangs up or slows down. It has big up-times.
6. Performance
Linux system provides high performance over different networks. It is capable of handling a
large number of users simultaneously.
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
Linux facilitates with powerful support for networking. The client-server systems can be
easily set to a Linux system. It provides various command-line tools such as ssh, ip, mail,
telnet, and more for connectivity with the other systems and servers. Tasks such as network
backup are much faster than others.
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
There are many command-line options that provide documentation on commands, libraries,
standards such as manual pages and info pages. Also, there are plenty of documents available
on the internet in different formats, such as Linux tutorials, Linux documentation project,
Serverfault, and more. To help the beginners, several communities are available such as Ask
Ubuntu, Reddit, and StackOverflow.
Linux Distributions (Distros)
Other operating systems like Microsoft combine each bit of codes internally and release it as
a single package. You have to choose from one of the version they offer.
But Linux is different from them. Different parts of Linux are developed by different
organizations.
Different parts include kernel, shell utilities, X server, system environment, graphical
programs, etc. If you want you can access the codes of all these parts and assemble them
yourself. But its not an easy task seeking a lot of time and all the parts has to be assembled
correctly in order to work properly.
From here on distribution (also called as distros) comes into the picture. They assemble all
these parts for us and give us a compiled operating system of Linux to install and use.
There are on an average six hundred Linux distributors providing different features. Here,
we'll discuss about some of the popular Linux distros today.
1) Ubuntu
It came into existence in 2004 by Canonical and quickly became popular. Canonical wants
Ubuntu to be used as easy graphical Linux desktop without the use of command line. It is the
most well known Linux distribution. Ubuntu is a next version of Debian and easy to use for
newbies. It comes with a lots of pre-installed apps and easy to use repositories libraries.
Earlier, Ubuntu uses GNOME2 desktop environment but now it has developed its own unity
desktop environment. It releases every six months and currently working to expand to run on
tablets and smartphones.
2) Linux Mint
Mint is based on Ubuntu and uses its repository software so some packages are common in
both.
Earlier it was an alternative of Ubuntu because media codecs and proprietary software are
included in mint but was absent in Ubuntu. But now it has its own popularity and it uses
cinnamon and mate desktop instead of Ubuntu's unity desktop environment.
3) Debian
Debian has its existence since 1993 and releases its versions much slowly then Ubuntu and
mint.
Ubuntu is based on Debian and was founded to improve the core bits of Debian more quickly
and make it more user friendly. Every release name of Debian is based on the name of the
movie Toy Story.
Red hat is a commercial Linux distributor. There products are red hat enterprise Linux
(RHEL) and Fedora which are freely available. RHEL is well tested before release and
supported till seven years after the release, whereas, fedora provides faster update and
without any support.
Red hat uses trademark law to prevent their software from being redistributed. CentOS is a
community project that uses red hat enterprise Linux code but removes all its trademark and
make it freely available. In other words, it is a free version of RHEL and provide a stable
platform for a long time.
5) Fedora
It is a project that mainly focuses on free software and provides latest version of software. It
doesn't make its own desktop environment but used 'upstream' software. By default it has
GNOME3 desktop environment. It is less stable but provides the latest stuff.
Linux mint It works like windows and should be use by new comers.
CentOS If you want to use red hat but without its trademark.
OpenSUSE It works same as Fedora but slightly older and more stable.
Arch Linux It is not for the beginners because every package has to be installed by yourself
LINUX LOADER
LILO (LInux LOader) is a boot loader (a small program that manages a dual boot) for use
with the Linux operating system. Most new computers are shipped with boot loaders for
some version of Microsoft Windows or the Mac OS. If a computer is to be used with Linux, a
special boot loader must be installed. LILO is the most popular boot loader among users who
employ Linux as their main, or only, operating system.When a computer is powered-up or
restarted with LILO installed in the usual manner, the basic input/output system (BIOS)
performs some initial tests and then transfers control to the Master Boot Record (MBR)
where LILO resides. The primary advantage of LILO is the fact that it allows for fast boot up
of Linux when installed in the MBR. Its main limitation is the fact that not all computers
tolerate modification of the MBR. In these situations, there are alternative approaches for
using LILO, but it takes longer.There are several boot loaders other than LILO that can be
used to boot Linux into a computer's memory, such as LOADLIN (LOAD LINux) and
GRUB (GRand Unified Bootloader).
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:
● 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.
● 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.
● A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)
Linux file system is generally a built-in layer of a Linux operating system used to handle the
data management of the storage. It helps to arrange the file on the disk storage. It manages
the file name, file size, creation date, and much more information about a file.
Linux file system has a hierarchal file structure as it contains a root directory and its
subdirectories. All other directories can be accessed from the root directory. A partition
usually has only one file system, but it may have more than one file system.
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.
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.
In Linux, the file system creates a tree structure. All the files are arranged as a tree and its
branches. The topmost directory called the root (/) directory. All other directories in Linux
can be accessed from the root directory.
● 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.
● 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.
● 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.
● 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.
When we install the Linux operating system, Linux offers many file systems such as Ext,
Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.
The file system Ext stands for Extended File System. It was primarily developed for MINIX
OS. The Ext file system is an older version, and is no longer used due to some limitations.
Ext2 is the first Linux file system that allows managing two terabytes of data. Ext3 is
developed through Ext2; it is an upgraded version of Ext2 and contains backward
compatibility. The major drawback of Ext3 is that it does not support servers because this file
system does not support file recovery and disk snapshot.
Ext4 file system is the faster file system among all the Ext file systems. It is a very
compatible option for the SSD (solid-state drive) disks, and it is the default file system in
Linux distribution.
2. JFS File System
JFS stands for Journaled File System, and it is developed by IBM for AIX Unix. It is an
alternative to the Ext file system. It can also be used in place of Ext4, where stability is
needed with few resources. It is a handy file system when CPU power is limited.
ReiserFS is an alternative to the Ext3 file system. It has improved performance and advanced
features. In the earlier time, the ReiserFS was used as the default file system in SUSE Linux,
but later it has changed some policies, so SUSE returned to Ext3. This file system
dynamically supports the file extension, but it has some drawbacks in performance.
XFS file system was considered as high-speed JFS, which is developed for parallel I/O
processing. NASA still using this file system with its high storage server (300+ Terabyte
server).
Btrfs stands for the B tree file system. It is used for fault tolerance, repair system, fun
administration, extensive storage configuration, and more. It is not a good suit for the
production system.
The swap file system is used for memory paging in Linux operating system during the system
hibernation. A system that never goes in hibernate state is required to have swap space equal
to its RAM size
Linux files are case sensitive, so test.txt and Test.txt will be considered as two different
files. There are multiple ways to create a file in Linux. Some conventional methods are as
follows:
Apart from all of the above methods, we can also create a file from the desktop file manager.
Let's understand the above methods in detail:
The cat command is one of the most used commands in Linux. It is used to create a file,
display the content of the file, concatenate the contents of multiple files, display the line
numbers, and more.
Here, we will see how to create files and add content to them using cat command.
First of all, create a directory and named it as New_directory, execute the mkdir command
as follows:
1. mkdir New_directory
1. cd New_directory
Output:
The above command will create a text file and will enter in the editor mode. Now, enter the
desired text and press CTRL + D key to save and exit the file and it will return to the
command line.
To display the content of the file, execute the cat command as follows:
1. cat test.txt
The touch command is also one of the popular commands in Linux. It is used to create a
new file, update the time stamp on existing files and directories. It can also create empty
files in Linux.
The touch command is the simplest way to create a new file from the command line. We can
create multiple files by executing this command at once.
To create a file, execute the touch command followed by the file name as given below:
1. touch test1.txt
To list the information of the created file, execute the below command:
1. ls - l test1.txt
To create multiple files at once, specify files and their extensions after the touch command
along with single space. Execute the below command to create three files at once:
The above command will create two different files named as test4.txt and test.odt.
To display the file and its timestamp, execute the ls command as follows:
1. ls -l
We can also create a file using the redirect symbol (>) on the command line. To create a file,
we just have to type a redirect symbol (>) followed by the file name. This symbol is mostly
used to redirect the output. There are two ways to redirect the output. If we use > operator, it
will overwrite the existing file, and >> operator will append the output.
To create a file with redirect (>) operator, execute the command as follows:
1. > test5.txt
The above command will create a file, to display the existence of the created file, execute the
below command:
1. ls -l test5.txt
The echo command is used to create a file, but we should specify the file content on the
command line.
To create the file with the echo command, execute the command as follows:
The above command will create the test6 file. To display the existence of the file, execute the
below command:
1. ls -l test6.txt
We can also create a file using printf command. For this we need to specify the file content
on the command line.
To create a file with the printf command, execute the command as follows:
1. ls -l test7.txt
1. cat test7.txt
We can also create a file using the different text editors like vim, nano, vi, and more.
We can create a file using the Vim text editor. If you do not have the vim editor installed on
your machine, execute the below command:
Output:
To create a file using the vim text editor, execute the below command:
1. vim test8.txt
The above command will open the text editor, press i key to go to the insert mode of the
editor.
Enter the file content, press Esc key preceded by :wq to save and exit the file. The text editor
looks like as follows:
1. cat test8.txt
We can create a file using the nano text editor. To create a file, execute the below command:
1. nano test9.txt
The above command will open the nano text editor. Enter the desired text and press CTRL +
X then type y for confirmation of the file changes. Press Enter key to exit from the editor.
1. ls -l test9.txt
1. cat test9.txt
1. vi test10.txt
The above command will open the Vi editor. Press i key for the insert mode and enter the file
content. Press Esc key and :wq to save and exit the file from the editor.
1. ls -l test10.txt
1. cat test10.txt