Linux Unit I

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

LINUX OPERATING SYSTEM

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.

Structure Of Linux Operating System

An operating system is a collection of software, each designed for a specific function.


1) Kernel

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.

5) End User Tools

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.

Why is Linux better than other operating systems?

1. pen Source

As it is open-source, its source code is easily available. Anyone having programming


knowledge can customize the operating system. One can contribute, modify, distribute, and
enhance the code for any purpose.
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 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.

10. Live CD/USB

Almost all Linux distributions have a Live CD/USB option. It allows us to try or run the
Linux operating system without installing it.

11. Graphical User Interface

Linux is a command-line based OS but, it provides an interactive user interface like


Windows.

12. Suitable for programmers

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.

13. Community Support

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.

18. Multiple Desktop Support

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

It is a multitasking operating system as it can run multiple tasks simultaneously without


affecting the system speed.

20. Heavily Documented for beginners

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.

Linux Distributions List

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.

This makes it one of the most stable Linux distributor.

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.

4) Red Hat Enterprise / CentOS

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.

Choosing a Linux Distro


Distribution Why To Use

UBuntu It works like Mac OS and easy to use.

Linux mint It works like windows and should be use by new comers.

Debian It provides stability but not recommended to a new user.

Fedora If you want to use red hat and latest software.

Red hat enterprise To be used commercially.

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).

Linux File System


A Linux file system is a structured collection of files on a disk drive or a partition. A partition
is a segment of memory and contains some specific data. In our machine, there can be various
partitions of the memory. Generally, every partition contains a file system.

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.

The Linux file system contains the following sections:

● The root directory (/)

● A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)

● A partition or logical volume having a particular file system.

What is the Linux File System?

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 Structure

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.

Linux File System Features

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.

Some key features of Linux file system are as following:

● 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.

● 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.

● 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.

Types of Linux File System

When we install the Linux operating system, Linux offers many file systems such as Ext,
Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.

Let's understand each of these file systems in detail:

1. Ext, Ext2, Ext3 and Ext4 file system

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.

3. ReiserFS File System

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.

4. XFS File System

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).

5. Btrfs File System

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.

6. Swap File 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 FILE RELATED COMMANDS

Linux Create File


Linux file system considers everything as a file in Linux; whether it is text file images,
partitions, compiled programs, directories, or hardware devices. If it is not a file, then it must
be a process. To manage the data, it forms a tree structure.

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:

● using cat command

● using touch command

● using redirect '>' symbol

● using echo command

● using printf command

● using a different text editor like vim, nano, vi

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:

1. Using cat command

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

Change directory to it:

1. cd New_directory
Output:

Now execute the cat command to create a file:

1. cat > test.txt

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

Consider the below output:

2. Using the touch command

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

Consider the below output:

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:

1. touch test1.txt test2.txt test3.txt

To create two different types of file, execute the command as follows:

1. touch test4.txt test.odt

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

Consider the below output:


If we pass the name of an existing file, it will change the timestamp of that file.

3. Using the redirect (>) symbol

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

Consider the below output:


4. Using echo command

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:

1. echo " File content" > test6.txt

The above command will create the test6 file. To display the existence of the file, execute the
below command:

1. ls -l test6.txt

consider the below output:

5. Using printf command

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. printf " File content" > test7.txt

To display the file details, execute the ls command as follows:

1. ls -l test7.txt

To display the file content, execute the cat command as follows:

1. cat test7.txt

Consider the below output:


6. Using Text Editor

We can also create a file using the different text editors like vim, nano, vi, and more.

● Using Vim text editor

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:

1. sudo apt install vim

Output:

The Vim text editor is successfully installed.

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:

To display the file information, execute the ls command as follows:


1. ls -l test8.txt

To view the file content, run the cat command as follows:

1. cat test8.txt

Consider the below output:

7. Using Nano editor

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.

The nano text editor looks like the below image:

To display the file information, execute the below command:

1. ls -l test9.txt

To view the file content, execute the below command:

1. cat test9.txt

Consider the below output:


Using Vi editor

To create a file with Vi editor, execute the below command:

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.

To display the file information, execute the below command:

1. ls -l test10.txt

To display the file content, execute the below command:

1. cat test10.txt

Consider the below output:

You might also like