Unit 1 Linux
Unit 1 Linux
UNIT 1
Linux Distribution
Architecture of Linux
1. Kernel: Kernel is the core of the Linux based operating system. It virtualizes the
common hardware resources of the computer to provide each process with its
virtual resources. This makes the process seem as if it is the sole process
running on the machine. The kernel is also responsible for preventing and
mitigating conflicts between different processes. Different types of the kernel
are:
Monolithic Kernel
Hybrid kernels
Exo kernels
Micro kernels
2. System Library: Isthe special types of functions that are used to implement the
functionality of the operating system.
3. Shell: It is an interface to the kernel which hides the complexity of the kernel’s
functions from the users. It takes commands from the user and executes the
kernel’s functions.
4. Hardware Layer: This layer consists all peripheral devices like RAM/ HDD/
CPU etc.
5. System Utility: It provides the functionalities of an operating system to the use
Advantages of Linux
Disadvantages of Linux
Basic Features
Following are some of the important features of Linux Operating System.
Portable − Portability means software can works on different types of
hardware in same way. Linux kernel and application programs supports their
installation on any kind of hardware platform.
Open Source − Linux source code is freely available and it is community
based development project. Multiple teams work in collaboration to enhance
the capability of Linux operating system and it is continuously evolving.
Multi-User − Linux is a multiuser system means multiple users can access
system resources like memory/ ram/ application programs at same time.
Multiprogramming − Linux is a multiprogramming system means multiple
applications can run at same time.
Hierarchical File System − Linux provides a standard file structure in which
system files/ user files are arranged.
Shell − Linux provides a special interpreter program which can be used to
execute commands of the operating system. It can be used to do various types
of operations, call application programs. etc.
Security − Linux provides user security using authentication features like
password protection/ controlled access to specific files/ encryption of data.
Architecture
The following illustration shows the architecture of a Linux system −
The architecture of a Linux System consists of the following layers-
Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/
CPU etc).
Kernel − It is the core component of Operating System, interacts directly with
hardware, provides low level services to upper layer components.
Shell − An interface to kernel, hiding complexity of kernel's functions from
users. The shell takes commands from the user and executes kernel's
functions.
Utilities − Utility programs that provide the user most of the functionalities of
an operating systems.
Different Shells in Linux
SHELL is a program which provides the interface between the user and an operating
system. When the user logs in OS starts a shell for user. Kernel controls all
essential computer operations, and provides the restriction to hardware access,
coordinates all executing utilities, and manages Resources between process. Using
kernel only user can access utilities provided by operating system.
Types of Shell:
The C Shell –
Denoted as csh
Bill Joy created it at the University of California at Berkeley. It incorporated
features such as aliases and command history. It includes helpful programming
features like built-in arithmetic and C-like expression syntax.
In C shell:
Command full-path name is /bin/csh,
Non-root user default prompt is hostname %,
Root user default prompt is hostname #.
The Bourne Shell –
Denoted as sh
It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It
is faster and more preferred. It lacks features for interactive use like the ability
to recall previous commands. It also lacks built-in arithmetic and logical
expression handling. It is default shell for Solaris OS.
Listing Files
To list the files and directories stored in the current directory, use the following
command −
$ls
Here is the sample output of the above command −
$ls
1
-
Regular file, such as an ASCII text file, binary executable, or hard link.
2
b
Block special file. Block input/output device file such as a physical hard drive.
3
c
Character special file. Raw input/output device file such as a physical hard drive.
4
d
Directory file that contains a listing of other files and directories.
5
l
Symbolic link file. Links on any regular file.
6
p
Named pipe. A mechanism for interprocess communications.
7
s
Socket used for interprocess communication.
Metacharacters
Metacharacters have a special meaning in Unix. For example, * and ? are
metacharacters. We use * to match 0 or more characters, a question mark (?)
matches with a single character.
For Example −
$ls ch*.doc
Displays all the files, the names of which start with ch and end with .doc −
ch01-1.doc ch010.doc ch02.doc ch03-2.doc
ch04-1.doc ch040.doc ch05.doc ch06-2.doc
ch01-2.doc ch02-1.doc c
Here, * works as meta character which matches with any character. If you want to
display all the files ending with just .doc, then you can use the following command −
$ls *.doc
Hidden Files
An invisible file is one, the first character of which is the dot or the period character
(.). Unix programs (including the shell) use most of these files to store configuration
information.
Some common examples of the hidden files include the files −
.profile − The Bourne shell ( sh) initialization script
.kshrc − The Korn shell ( ksh) initialization script
.cshrc − The C shell ( csh) initialization script
.rhosts − The remote shell configuration file
To list the invisible files, specify the -a option to ls −
$ ls -a
. .profile docs lib test_results
.. .rhosts hosts pub users
.emacs bin hw1 res.01 work
.exrc ch07 hw2 res.02
.kshrc ch07.bak hw3 res.03
$
Single dot (.) − This represents the current directory.
Double dot (..) − This represents the parent directory.
Linux is based on UNIX and hence it borrows its filesystem hierarchy from UNIX. You’ll
fine a similar directory structure in UNIX-like operating systems such as BSD and
macOS. I’ll be using the term Linux hereafter instead of UNIX though.
Everything, all the files and directories, in Linux are located under ‘root’ represented by
‘/’. If you look at the directory structure, you’ll realize that it is similar to a plant’s root.
Since all other directories or files are descended from root, the absolute path of any file
is traversed through root. For example, if you have a file in /home/user/documents, you
can guess that the directory structure goes from root->home->user->documents.
/bin – Binaries
The ‘/bin’ directly contains the executable files of many basic shell commands like
ls, cp, cd etc. Mostly the programs are in binary format here and accessible by all the
users in the Linux system.
This directory only contains special files, including those relating to the devices. These
are virtual files, not physically on the disk.
The /etc directory contains the core configuration files of the system, use primarily by
the administrator and services, such as the password file and networking files.
If you need to make changes in system configuration (for example changing the
hostname), this is where you’ll find the respective files.
in ‘/usr’ go all the executable files, libraries, source of most of the system programs. For
this reason, most of the files contained therein is readonly (for the normal user)
Home directory contains personal directories for the users. The home directory
contains the user data and user-specific configuration files. As a user, you’ll put your
personal files, notes, programs etc in your home directory.
When you create a user on your Linux system, it’s a general practice to create a home
directory for the user. Suppose your Linux system has two users, Alice and Bob. They’ll
have a home directory of their own at locations /home/alice and /home/bob.
Do note that Bob won’t have access to /home/alice and vice versa. That makes sense
because only the user should have access to his/her home. You may read about file
permissions in Linux to know more on this topic.
/lib – Shared libraries
Libraries are basically codes that can be used by the executable binaries. The /lib
directory holds the libraries needed by the binaries in /bin and /sbin directories.
Libraries needed by the binaries in the /usr/bin and /usr/sbin are located in the
directory /usr/lib.
This is similar to the /bin directory. The only difference is that is contains the binaries
that can only be run by root or a sudo user. You can think of the ‘s’ in ‘sbin’ as super or
sudo.
As the name suggests, this directory holds temporary files. Many applications use this
directory to store temporary files. Even you can use directory to store temporary files.
But do note that the contains of the /tmp directories are deleted when your system
restarts. Some Linux system also delete files old files automatically so don’ store
anything important here.
Var, short for variable, is where programs store runtime information like system
logging, user tracking, caches, and other files that system programs create and manage.
The files stored here are NOT cleaned automatically and hence it provides a good place
for system administrators to look for information about their system behavior. For
example, if you want to check the login history in your Linux system, just check the
content of the file in /var/log/wtmp.
The ‘/boot’ directory contains the files of the kernel and boot image, in addition to LILO
and Grub. It is often advisable that the directory resides in a partition at the beginning
of the disc.
The ‘/proc’ directory contains the information about currently running processes and
kernel parameters. The content of the proc directory is used by a number of tools to get
runtime system information.
For example, if you want to check processor information in Linux, you can simply refer
to the file /proc/cpuinfo. You want to check memory usage of your Linux system, just
look at the content of /proc/meminfo file.
/opt – Optional software
Traditionally, the /opt directory is used for installing/storing the files of third-party
applications that are not available from the distribution’s repository.
The normal practice is to keep the software code in opt and then link the binary file in
the /bin directory so that all the users can run it.
There is /root directory as well and it works as the home directory of the root user. So
instead of /home/root, the home of root is located at /root. Do not confuse it with the
root directory (/).
When you connect a removable media such as USB disk, SD card or DVD, a directory is
automatically created under the /media directory for them. You can access the content
of the removable media from this directory.
This is similar to the /media directory but instead of automatically mounting the
removable media, mnt is used by system administrators to manually mount a
filesystem.
The /srv directory contains data for services provided by the system. For example, if
you run a HTTP server, it’s a good practice to store the website data in the /srv
directory.
I think this much information is enough for you to understand the Linux directory
structure and its usage.
In the end, if you want, you can download and save this image for quick reference to the
directory structure in Linux systems.
Linux System Directories
What is System Call in Operating System?
A system call is a mechanism that provides the interface between a process
and the operating system. It is a programmatic method in which a computer
program requests a service from the kernel of the OS.
System call offers the services of the operating system to the user programs
via API (Application Programming Interface). System calls are the only entry
points for the kernel system.
There are many different system calls as shown above. Details of some of those
system calls are as follows −
wait()
In some systems, a process may wait for another process to complete its execution.
This happens when a parent process creates a child process and the execution of the
parent process is suspended until the child process executes. The suspending of the
parent process occurs with a wait() system call. When the child process completes
execution, the control is returned back to the parent process.
exec()
This system call runs an executable file in the context of an already running process.
It replaces the previous executable file. This is known as an overlay. The original
process identifier remains since a new process is not created but data, heap, stack
etc. of the process are replaced by the new process.
fork()
Processes use the fork() system call to create processes that are a copy of
themselves. This is one of the major methods of process creation in operating
systems. When a parent process creates a child process and the execution of the
parent process is suspended until the child process executes. When the child process
completes execution, the control is returned back to the parent process.
exit()
The exit() system call is used by a program to terminate its execution. In a
multithreaded environment, this means that the thread execution is complete. The
operating system reclaims resources that were used by the process after the exit()
system call.
kill()
The kill() system call is used by the operating system to send a termination signal to a
process that urges the process to exit.However, kill system call does not necessary
mean killing the process and can have various meanings.
S
system Calls in Operating System
Example of System Call
For example if we need to write a program code to read data from one file,
copy that data into another file. The first information that the program
requires is the name of the two files, the input and output files.
Step 1) The processes executed in the user mode till the time a system call
interrupts it.
Step 2) After that, the system call is executed in the kernel-mode on a priority
basis.
Step 3) Once system call execution is over, control returns to the user mode.,
segment of memory and contains some specific data. In our machine, there can be various
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
o turned off. However, there is non-volatile RAM (Flash RAM and SSD) that is available to
o maintain the data after the power interruption.
o Data storage is preferred on hard drives as compared to standard RAM as RAM costs more
o than disk space. The hard disks costs are dropping gradually comparatively the RAM.
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.
If we have an unsupported file format in our file system, we can download software to deal with it.
Linux File System Structure
Linux file system has a hierarchal file structure as it contains a root directory and its subdirectories.
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
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 modifiedAlso, it stores
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
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
The first two parts of the given file system together called a Linux virtual file system. It provides
and developers to access the file system. This virtual file system requires the specific system driver t
branches. The topmost directory called the root (/) directory. All other directories in Linux
o Specifying paths: Linux does not use the backslash (\) to separate the components;
o it uses forward slash (/) as an alternative. For example, as in Windows, the data may be
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 netw
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
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
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
The major drawback of Ext3 is that it does not support servers because this file system does not
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.
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
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
1. This location is good for storage because this place doesn’t require initialization
and moreover location here it is fixed so that processor can start executing
when powered up or reset.
The problem is that changing the bootstrap code basically requires changes in the
ROM hardware chips.Because of this reason, most system nowadays has the tiny
bootstrap loader program in the boot whose only job is to bring the full bootstrap
program from the disk. Through this now we are able to change the full bootstrap
program easily and the new version can be easily written onto the disk.
Full bootstrap program is stored in the boot blocks at a fixed location on the disk. A
disk which has a boot partition is called a boot disk. The code in the boot ROM
basically instructs the read controller to read the boot blocks into the memory and
then starts the execution of code. The full bootstrap program is more complex than
the bootstrap loader in the boot ROM, It is basically able to load the complete OS
from a non-fixed location on disk to start the operating system running. Even though
the complete bootstrap program is very small.
and more.
Linux Inodes
An Inode number is a uniquely existing number for all the files in Linux and all Unix
type systems.
When a file is created on a system, a file name and Inode number is assigned to it.
Generally, to access a file, a user uses the file name but internally file name is first
mapped with respective Inode number stored in a table.
Note: Inode doesn't contain the file name. Reason for this is to maintain hard-links
for the files. When all the other information is separated from the file name then only
we can have various file names pointing to the same Inode.
Inode Contents
An Inode is a data structure containing metadata about the files.
Example:
1. ls -ld new1
Inode Table
The Inode table contains all the Inodes and is created when file system is created.
The df -i command can be used to check how many inodes are free and left unused in
the filesystem.
Look at the above snapshot, the command "df -i" shows the usage of several file
systems.
Inode Number
Each Inode has a unique number and Inode number can be seen with the help of ls -
li command.
Look at the above snapshot, Directory Disk1 has the three files and each file has a
different Inode number.
Note: The Inode doesn't contain file content, instead it has a pointer to that data.
data blocks start at the end of the inode list and contain
file data and directory blocks.
The term file system can mean a single disk, or it can mean
the entire collection of devices on a system. It's held together
in this second sense by the directory structure.
The directory "tree" usually spans many disks and/or
partitions by means of mount points. For example, in Red Hat
Linux, there are pre-defined mount points for floppy disks and
CD-ROMs at floppy and cdrom in /mnt. See
also fstab and mtab in /etc.