0% found this document useful (0 votes)
512 views

Unit-V Linux - History and Evolution

The document discusses the history and evolution of Linux. It begins with the origins of UNIX at Bell Labs in the 1960s. Linux was created in 1991 by Linus Torvalds because he could not afford commercial versions of UNIX and wanted an open-source alternative. Linux combines the Linux kernel with software from the GNU project to form a free and open-source operating system. It then discusses the file hierarchy, directory structure, and common commands used in Linux systems.

Uploaded by

Mohit Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
512 views

Unit-V Linux - History and Evolution

The document discusses the history and evolution of Linux. It begins with the origins of UNIX at Bell Labs in the 1960s. Linux was created in 1991 by Linus Torvalds because he could not afford commercial versions of UNIX and wanted an open-source alternative. Linux combines the Linux kernel with software from the GNU project to form a free and open-source operating system. It then discusses the file hierarchy, directory structure, and common commands used in Linux systems.

Uploaded by

Mohit Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

UNIT-V

Linux– History and Evolution


In this article, we will discuss the history and evolution of the Linux Operating
System. But before jumping into the history of Linux we must pass through UNIX.
History of UNIX:
It started in 1964 in New Jersey when some people of Bell Labs tried to create a
multiuser operating system (OS), they worked on it till 1969, after facing lots of
failures they withdraw the project. Then a group of five people including Dennis
Ritchie and Ken Thompson successfully created an operating system called UNICS
(Uniplexed Information and Computing Service), better known as UNIX. They
publish this OS as open-source (free to use and edit the codebase).
In 1975 a version of UNIX was released labeled “UNIX v6”, it became very popular.
Some companies tried to make a profit from it, so they made their own commercial
version or flavor of UNIX:
• IBM – AIX
• Sun Solaris
• Mac OS
• UP UX
Why Linux was created?
Linus Torvalds is the creator of the Linux kernel. In simple words, Linus Torvalds
created Linux because he didn’t have money to buy UNIX. He was a student at the
*University of Helsinki*. In early 1991 he decided to do a project on UNIX, but free
versions of UNIX were too old and other commercials are too costly ($5000). So, he
thought of creating his own OS.
Finally, Linux was released on September 17, 1991. Linus made it open source.
Between 1991 to 1995, Richard Stallman started a movement called the “Free Software
Movement“, and created the GNU project (collection of free software).
Linux is a kernel and not an operating system and GNU is a collection of free software,
these two project collabs give us “Linux” or “GNU/Linux” operating system. Some
companies and open-source communities adopt GNU/Linux codebase, did some
modifications, and created their own version or distributions, Example:
• RHEL (Red hat)
• Fedora
• Debian
• Ubuntu
• CentOS
• Kali Linux
Note:
• Linux is a kernel, not OS.
• Linux is not a UNIX clone; it was written from scratch.
• A Linux distribution is the Linux kernel and a collection of software that
together creates an OS.
Linux File Hierarchy Structure
The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines
the directory structure and directory contents in Unix-like operating systems. It is
maintained by the Linux Foundation.
• In the FHS, all files and directories appear under the root directory /, even if
they are stored on different physical or virtual devices.
• Some of these directories only exist on a particular system if certain
subsystems, such as the X Window System, are installed.
• Most of these directories exist in all UNIX operating systems and are
generally used in much the same way; however, the descriptions here are
those used specifically for the FHS and are not considered authoritative for
platforms other than Linux.

Linux Directory Structure


In Linux/Unix operating system everything is a file even directories are files, files are
files, and devices like mouse, keyboard, printer, etc are also files. Here we are going to
see the Directory Structure in Linux.
Types of files in the Linux system.
1. General Files – It is also called ordinary files. It may be an image, video,
program, or simple text files. These types of files can be in ASCII or Binary
format. It is the most commonly used file in the Linux system.
2. Directory Files – These types of files are a warehouse for other file types. It
may be a directory file within a directory (subdirectory).
3. Device Files – In a Windows-like operating system, devices like CD-ROM,
and hard drives are represented as drive letters like F: G: H whereas in the
Linux system device are represented as files. As for example, /dev/sda1,
/dev/sda2 and so on.

We know that Windows-like operating system, files are stored in different folders on
different data drives like C: D: E: whereas in the Linux/Unix operating system files are
stored in a tree-like structure starting with the root directory as shown in the below
diagram.
The base of the Linux/Unix file system hierarchy begins at the root and everything starts
with the root directory.
These are the common top-level directories associated with the root
directory:
• /bin – binary or executable programs.
• /etc – system configuration files.
• /home – home directory. It is the default current directory.
• /opt – optional or third-party software.
• /tmp – temporary space, typically cleared on reboot.
• /usr – User related programs.
• /var – log files.

Examples of Linux Directory Commands


Directory Description
Command

pwd The pwd command stands for (print working directory). It displays the
current working location or directory of the user. It displays the whole
working path starting with /. It is a built-in command.

ls The ls command is used to show the list of a folder. It will list out all the
files in the directed folder.

cd The cd command stands for (change directory). It is used to change to


the directory you want to work from the present directory.

mkdir With mkdir command you can create your own directory.

rmdir The rmdir command is used to remove a directory from your system.

Examples of Linux File handling Commands

1. Files Listing
To perform Files listings or to list files and directories ls command is used
$ls

All your files and directories in the current directory would be listed and each type of
file would be displayed with a different color. Like in the output directories are
displayed with dark blue color.
$ls -l

It returns the detailed listing of the files and directories in the current directory. The
command gives os the owner of the file and even which file could be managed by
which user or group and which user/group has the right to access or execute which
file.
2. Creating Files
touch command can be used to create a new file. It will create and open a new blank
file if the file with a filename does not exist. And in case the file already exists then
the file will not be affected.
$touch filename

3. Displaying File Contents


cat command can be used to display the contents of a file. This command will display
the contents of the ‘filename’ file. And if the output is very large then we could use
more or less to fit the output on the terminal screen otherwise the content of the whole
file is displayed at once.
$cat filename

4. Copying a File
cp command could be used to create the copy of a file. It will create the new file in
destination with the same name and content as that of the file ‘filename’.
$cp source/filename destination/
5. Moving a File
mv command could be used to move a file from source to destination. It will remove
the file filename from the source folder and would be creating a file with the same
name and content in the destination folder.
$mv source/filename destination/

6. Renaming a File
mv command could be used to rename a file. It will rename the filename to
new_filename or in other words, it will remove the filename file and would be creating
a new file with the new_filename with the same content and name as that of the
filename file.
$mv filename new_filename

7. Deleting a File
rm command will remove the filename file from the directory.
$rm filename

Absolute and Relative Pathnames in UNIX


A path is a unique location to a file or a folder in a file system of an OS. A path to a file
is a combination of / and alpha-numeric characters.
Absolute Path-name
An absolute path is defined as the specifying the location of a file or directory from the
root directory (/). To write an absolute path-name:
• Start at the root directory (/) and work down.
• Write a slash (/) after every directory name (last one is optional)
For Example:
cat /home/kt/abc.sql
An absolute path is defined as specifying the location of a file or directory from the root
directory (/). In other words, we can say that an absolute path is a complete path from
start of actual file system from / directory.

Relative path-name
Relative path is defined as the path related to the present working directly(pwd). It
starts at your current directory and never starts with a /.
To be more specific let’s take a look on the below figure in which if we are looking
for photos then absolute path for it will be provided as /home/jono/photos but assuming
that we are already present in jono directory then the relative path for the same
can be written as simple photos.

Architecture of Linux
Linux architecture has the following components:
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
user.
Advantages of Linux
• The main advantage of Linux, is it is an open-source operating system.
This means the source code is easily available for everyone and you are
allowed to contribute, modify and distribute the code to anyone without any
permissions.
• In terms of security, Linux is more secure than any other operating system.
It does not mean that Linux is 100 percent secure it has some malware for
it but is less vulnerable than any other operating system. So, it does not
require any anti-virus software.
• The software updates in Linux are easy and frequent.
• Various Linux distributions are available so that you can use them
according to your requirements or according to your taste.
• Linux is freely available to use on the internet.
• It has large community support.
• It provides high stability. It rarely slows down or freezes and there is no
need to reboot it after a short time.
• It maintains the privacy of the user.
• The performance of the Linux system is much higher than other operating
systems. It allows a large number of people to work at the same time and it
handles them efficiently.
• It is network friendly.
• The flexibility of Linux is high. There is no need to install a complete Linux
suit; you are allowed to install only required components.
• Linux is compatible with a large number of file formats.
• It is fast and easy to install from the web. It can also install on any hardware
even on your old computer system.
Disadvantages of Linux
• It is not very user-friendly. So, it may be confusing for beginners.
• It has small peripheral hardware drivers as compared to windows.

Introduction to Linux Shell and Shell Scripting


If you are using any major operating system, you are indirectly interacting to shell. If
you are running Ubuntu, Linux Mint or any other Linux distribution, you are
interacting to shell every time you use terminal. In this article I will discuss about
linux shells and shell scripting so before understanding shell scripting we have to get
familiar with following terminologies:
• Kernel
• Shell
• Terminal
What is Kernel
The kernel is a computer program that is the core of a computer’s operating system,
with complete control over everything in the system. It manages following resources
of the Linux system –
• File management
• Process management
• I/O management
• Memory management
• Device management etc.
What is Shell
A shell is special user program which provide an interface to user to use operating
system services. Shell accept human readable commands from user and convert them
into something which kernel can understand. It is a command language interpreter that
execute commands read from input devices such as keyboards or from files. The shell
gets started when the user logs in or start the terminal.
Shell is broadly classified into two categories –
• Command Line Shell
• Graphical shell
Command Line Shell
Shell can be accessed by user using a command line interface. A special program
called Terminal in linux/macOS or Command Prompt in Windows OS is provided to
type in the human readable commands such as “cat”, “ls” etc. and then it is being
execute. The result is then displayed on the terminal to the user. A terminal in Ubuntu
16.4 system looks like this –

In above screenshot “ls” command with “-l” option is executed.


It will list all the files in current working directory in long listing format.
Working with command line shell is bit difficult for the beginners because it’s hard to
memorize so many commands. It is very powerful; it allows user to store commands
in a file and execute them together. This way any repetitive task can be easily
automated. These files are usually called batch files in Windows and Shell Scripts in
Linux/macOS systems.
Graphical Shells
Graphical shells provide means for manipulating programs based on graphical user
interface (GUI), by allowing for operations such as opening, closing, moving and
resizing windows, as well as switching focus between windows. Window OS or
Ubuntu OS can be considered as good example which provide GUI to user for
interacting with program. User do not need to type in command for every actions.A
typical GUI in Ubuntu system –
There are several shells are available for Linux systems like –
• BASH (Bourne Again SHell) – It is most widely used shell in Linux systems.
It is used as default login shell in Linux systems and in macOS. It can also
be installed on Windows OS.
• CSH (C SHell) – The C shell’s syntax and usage are very similar to the C
programming language.
• KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell
standard specifications etc.
Each shell does the same job but understand different commands and provide different
built-in functions.
Shell Scripting
Usually shells are interactive that mean, they accept command as input from users and
execute them. However, some time we want to execute a bunch of commands
routinely, so we have type in all commands each time in terminal.
As shell can also take commands as input from file we can write these commands in
a file and can execute them in shell to avoid this repetitive work. These files are
called Shell Scripts or Shell Programs. Shell scripts are similar to the batch file in
MS-DOS. Each shell script is saved with .sh file extension eg. myscript.sh
A shell script comprises following elements –
• Shell Keywords – if, else, break etc.
• Shell commands – cd, ls, echo, pwd, touch etc.
• Functions
• Control flow – if..then..else, case and shell loops etc.
Why do we need shell scripts?
There are many reasons to write shell scripts:
• To avoid repetitive work and automation
• System admins use shell scripting for routine backups
• System monitoring
• Adding new functionality to the shell etc.
Advantages of shell scripts
• The command and syntax are exactly the same as those directly entered in
command line, so programmer do not need to switch to entirely different
syntax
•Writing shell scripts are much quicker
•Quick start
• Interactive debugging etc.
Disadvantages of shell scripts
• Prone to costly errors, a single mistake can change the command which
might be harmful
• Slow execution speed
• Design flaws within the language syntax or implementation
• Not well suited for large and complex task
• Provide minimal data structure unlike other scripting languages. etc

Basic Shell Commands in Linux


A shell is a special user program that provides an interface to the user to use operating
system services. Shell accepts human-readable commands from the user and converts
them into something which the kernel can understand. It is a command language
interpreter that executes commands read from input devices such as keyboards or from
files. The shell gets started when the user logs in or starts the terminal.
1). Displaying the file contents on the terminal:
• cat: It is generally used to concatenate the files. It gives the output on the
standard output.
• more: It is a filter for paging through text one screenful at a time.
• less: It is used to viewing the files instead of opening the file.Similar
to more command but it allows backward as well as forward movement.
• head : Used to print the first N lines of a file. It accepts N as input and the
default value of N is 10.
• tail : Used to print the last N-1 lines of a file. It accepts N as input and the
default value of N is 10.

2). File and Directory Manipulation Commands:


• mkdir : Used to create a directory if not already exist. It accepts the directory
name as an input parameter.
• cp : This command will copy the files and directories from the source path to
the destination path. It can copy a file/directory with the new name to the
destination path. It accepts the source file/directory and destination
file/directory.
• mv : Used to move the files or directories. This command’s working is almost
similar to cp command but it deletes a copy of the file or directory from the
source path.
• rm : Used to remove files or directories.
• touch : Used to create or update a file.

3). Extract, sort, and filter data Commands:


• grep : This command is used to search for the specified text in a file.
• sort : This command is used to sort the contents of files.
• wc : Used to count the number of characters, words in a file.
• cut : Used to cut a specified part of a file.
4). Basic Terminal Navigation Commands:
• ls : To get the list of all the files or folders.
• ls -l: Optional flags are added to ls to modify default behavior, listing
contents in extended form -l is used for “long” output
• ls -a: Lists of all files including the hidden files, add -a flag
• cd: Used to change the directory.
• du: Show disk usage.
• pwd: Show the present working directory.
• man: Used to show the manual of any command present in Linux.
• rmdir: It is used to delete a directory if it is empty.
• ln file1 file2: Creates a physical link.
• ln -s file1 file2: Creates a symbolic link.
• locate: It is used to locate a file in Linux System
• echo: This command helps us move some data, usually text into a file.
• df: It is used to see the available disk space in each of the partitions in your
system.
• tar: Used to work with tarballs (or files compressed in a tarball archive)
5). File Permissions Commands: The chmod and chown commands are used to
control access to files in UNIX and Linux systems.
• chown : Used to change the owner of the file.
• chgrp : Used to change the group owner of the file.
• chmod : Used to modify the access/permission of a user.

Basic Operators in Shell Scripting


There are 5 basic operators in bash/shell scripting:
• Arithmetic Operators
• Relational Operators
• Boolean Operators
• Bitwise Operators
• File Test Operators
1. Arithmetic Operators: These operators are used to perform normal arithmetical
/mathematical operations. There are 7 arithmetic operators:
• Addition (+): Binary operation used to add two operands.
• Subtraction (-): Binary operation used to subtract two operands.
• Multiplication (*): Binary operation used to multiply two operands.
• Division (/): Binary operation used to divide two operands.
• Modulus (%): Binary operation used to find remainder of two operands.
• Increment Operator (++): Unary operator used to increase the value of
operand by one.
• Decrement Operator (- -): Unary operator used to decrease the value of a
operand by one.

2. Relational Operators: Relational operators are those operators which define the
relation between two operands. They give either true or false depending upon the
relation. They are of 6 types:
• ‘==’ Operator: Double equal to operator compares the two operands. Its
returns true is they are equal otherwise returns false.
• ‘! =’ Operator: Not Equal to operator return true if the two operands are
not equal otherwise it returns false.
• ‘<’ Operator: Less than operator returns true if first operand is less than
second operand otherwise returns false.
• ‘<=’ Operator: Less than or equal to operator returns true if first operand
is less than or equal to second operand otherwise returns false
• ‘>’ Operator: Greater than operator return true if the first operand is greater
than the second operand otherwise return false.
• ‘>=’ Operator: Greater than or equal to operator returns true if first operand
is greater than or equal to second operand otherwise returns false.

3. Logical Operators: They are also known as Boolean operators. These are used to
perform logical operations. They are of 3 types:
• Logical AND (&&): This is a binary operator, which returns true if both
the operands are true otherwise returns false.
• Logical OR (||): This is a binary operator, which returns true is either of the
operand is true or both the operands are true and return false if none of them
is false.
• Not Equal to (!): This is a unary operator which returns true if the operand
is false and returns false if the operand is true.

4. Bitwise Operators: A bitwise operator is an operator used to perform bitwise


operations on bit patterns. They are of 6 types:
• Bitwise And (&): Bitwise & operator performs binary AND operation bit
by bit on the operands.
• Bitwise OR (|): Bitwise | operator performs binary OR operation bit by bit
on the operands.
• Bitwise XOR (^): Bitwise ^ operator performs binary XOR operation bit
by bit on the operands.
• Bitwise complement (~): Bitwise ~ operator performs binary NOT
operation bit by bit on the operand.
• Left Shift (<<): This operator shifts the bits of the left operand to left by
number of times specified by right operand.
• Right Shift (>>): This operator shifts the bits of the left operand to right by
number of times specified by right operand.
5. File Test Operator: These operators are used to test a particular property of a file.
• -b operator: This operator checks whether a file is a block special file or
not. It returns true if the file is a block special file otherwise false.
• -c operator: This operator checks whether a file is a character special file
or not. It returns true if it is a character special file otherwise false.
• -d operator: This operator checks if the given directory exists or not. If it
exists then operators return true otherwise false.
• -e operator: This operator checks whether the given file exists or not. If it
exits this operator returns true otherwise false.
• -r operator: This operator checks whether the given file has read access or
not. If it has read access then it returns true otherwise false.
• -w operator: This operator checks whether the given file has write access
or not. If it has write then it returns true otherwise false.
• -x operator: This operator checks whether the given file has execute access
or not. If it has execute access then it returns true otherwise false.
• -s operator: This operator checks the size of the given file. If the size of
given file is greater than 0 then it returns true otherwise it is false.
chmod command in Linux
In Unix-like operating systems, the chmod command is used to change the access mode
of a file.
The name is an abbreviation of change mode.
Syntax :
chmod [reference][operator][mode] file...
The references are used to distinguish the users to whom the permissions apply i.e. they
are list of letters that specifies whom to give permissions. The references are represented
by one or more of the following letters:
Reference Class Description
u user file's owner
g group users who are members of the file's group
o others users who are neither the file's owner nor members of the file's group
a all All three of the above, same as ugo

The operator is used to specify how the modes of a file should be adjusted. The
following operators are accepted:
Operator Description
+ Adds the specified modes to the specified classes
- Removes the specified modes from the specified classes
= The modes specified are to be made the exact modes for the specified classes
Note: Putting blank space(s) around operator would make the command fail.
The modes indicate which permissions are to be granted or removed from the specified
classes. There are three basic modes which correspond to the basic permissions:
r Permission to read the file.
w Permission to write (or delete) the file.
x Permission to execute the file, or, in the case of a directory, search it.
Types of permissions which we will be changing using chmod command :
In linux terminal, to see all the permissions to different files, type ls -l command which
lists the files in the working directory in long format. The figure below shows an
example to use ls -l and its output :

Let us take a look at above figure. To make things easy to understand some columns
and rows are eliminated and extra spaces are added to the permissions column to make
it easier to read as shown below:
- rw- rw- r-- mik mik assgn1_client.c
- rw- rw- r-- mik mik assgn1_server.c
d rwx rwx r-x mik mik EXAM
Now, let us see how chmod command can be used to change the access mode of a file.
Example 1 :
Let’s change the assgn1_client.c permission so that the owner cannot write(w) in the
file but can only read it.
BEFORE: -rw-rw-r-- mik mik assgn1_client.c
COMMAND: chmod u=r assgn1_client.c
AFTER: -r--rw-r-- mik mik assgn1_client.c
Before :

After :

Example 2 :
Let’s restrict the permission such that the user cannot search the directory EXAM.
BEFORE: drwxrwxr-x mik mik EXAM
COMMAND: chmod u=rw EXAM
AFTER: drw-rwxr-x mik mik EXAM
After applying the chmod u=rw EXAM command, the user (owner) cannot change the
directory. If the user tries to change the directory, then it shows the message
“Permission denied” as shown in the figure below :

chroot command in Linux


chroot command in Linux/Unix system is used to change the root directory. Every process/command
in Linux/Unix like systems has a current working directory called root directory. It changes the root
directory for currently running processes as well as its child processes.
A process/command that runs in such a modified environment cannot access files outside the root
directory. This modified environment is known as “chroot jail” or “jailed directory”. Some root user
and privileged process are allowed to use chroot command.
“chroot” command can be very useful:
• To create a test environment.
• To recover the system or password.
• To reinstall the bootloader.
Syntax:
chroot /path/to/new/root command OR
chroot /path/to/new/root /path/to/server OR
chroot [options] /path/to/new/root /path/to/server
Example:
• Step 1: We will create a mini-jail with bash and basic commands only. Let’s create a “jail”
directory inside the “home” directory, which will be our new root.

$ mkdir $HOME/jail
• Step 2: Create directories inside “$HOME/jail”:

$ mkdir -p $HOME/jail/{bin, lib64}


$ cd $HOME/jail
• Step 3: Copy /bin/bash and /bin/ls into $HOME/jail/bin/ location using cp command:

$ cp -v /bin/{bash, ls} $HOME/jail/bin


• Step 4: Use ldd command to print shared libraries:

$ ldd /bin/bash
• Step 5: Copy required libraries into $HOME/jail/lib64/ location using cp command:

cp -v libraries/displayed/by/above/command $HOME/jail/lib64
Similarly, copy the libraries of ls command into $HOME/jail/lib64 location.
• Step 6: Finally, chroot into your mini-jail:

$ sudo chroot $HOME/jail /bin/bash


Now user sees $HOME/jail directory as its root directory. This is a great boost in the security.

You might also like