You are on page 1of 53

Introduction to Linux

Unit - II
What is
Linux?

It’s an
Operating
System
What is
Linux?

The Most Common


O/S Used By
Researchers When
Working on a
Server or
Computer Cluster
What is Linux?
 Linux is a Unix clone written from scratch by
Linus Torvalds with assistance from a loosely-
knit team of hackers across the Net.
 Unix is a multitasking, multi-user computer

operating system originally developed in 1969


by a group of AT&T employees at Bell Labs.
 Linux and Unix strive to be POSIX compliant.
 64% of the world’s servers run some variant of

Unix or Linux. The Android phone and the


Kindle run Linux.
Advantages
 Open Source. One of the main advantages of
Linux is that it is an open-source operating
system, i.e. its source code is easily available to
everyone. ...
 Security. ...
 Performance. ...
 Software Updates. ...
 Multitasking. ...
 Various Distributions. ...
 Fast and easy installation ...
 Network friendliness.
Benefits of Linux
 Linux has no cost
 Linux has no royalty, Linux provides an

excellent return on investment


 Linux is made to work on a desktop and as a

server
 Linux is fast and secure
 Linux is stable
 Linux works on a variety of hardware
 Linux supports multi processor computers
Linux Has Many Distributions
Linux commands
 Linux is a Unix-Like operating system. All the
Linux/Unix commands are run in the terminal
provided by the Linux system.
 This terminal is just like the command prompt

of Windows OS. Linux/Unix commands


are case-sensitive.
 Linux terminal is user-interactive. The terminal

outputs the results of commands which are


specified by the user itself.
 Execution of typed command is done only after

you press the Enter key.


Linux commands
“Small programs that do one thing well”
(see unix-reference.pdf)

 Network: ssh, scp, ping, telnet, nslookup, wget


 Shells: BASH, TCSH, alias, watch, clear, history, chsh, echo, set,
setenv, xargs
 System Information: w, whoami, man, info, which, free, echo,
date, cal, df, free, man, info
 Command Information: man, info
 Symbols: |, >, >>, <, &, >&, 2>&1, ;, ~, ., .., $!, !:<n>, !<n>
 Filters: grep, egrep, more, less, head, tail
 Hotkeys: <ctrl><c>, <ctrl><d>
 File System: ls, mkdir, cd, pwd, mv, ln, touch, cat, file, find,
diff, cmp, /net/<hostname>/<path>, mount, du, df, chmod,
find
 Line Editors: awk, sed
 File Editors: vim, gvim, emacs –nw, emacs
User Mode
 Whenever you run an application in your
computer system, it runs in the user mode.
 When opening the program in user mode, it is

not allowed to access the RAM and hardware


directly. To access the hardware and RAM in
user mode, it sends a request to the kernel.
 That is the reason user mode is also known

as slave mode, or restricted mode.


Kernal mode
 When we start our system, it boots in Kernel
mode. The kernel can access the hardware
and RAM of the system directly.
 There are some privileged instructions that

can run in the kernel mode only. These


instructions are interrupt instructions, input-
output management, etc.
 If these privileged instructions get executed

under the user mode, it is not legal and it


may cause an illegal trap.
Difference between kernel mode and
user mode
Aspect User Mode Kernel Mode
Privilege Level Lower-privileged Higher-privileged

Access to Hardware Restricted Unrestricted

Access to System Memory Limited Full access

Operating system and kernel


Execution Environment User-level applications
components

Processes in User Mode are Kernel manages process


Error Isolation
isolated isolation

Manage system resources


Purpose Run user applications
and hardware

Limited exception handling Comprehensive exception


Exception Handling
capabilities handling

Application crashes do not Kernel issues can crash the


Stability
crash OS entire OS
The Linux File System
 The *Nix (Unix or Linux) file system is a hierarchical
directory structure
 The structure resembles an upside down tree
 Directories are collections of files and other
directories. The structure is recursive with many levels.
 Every directory has a parent except for the
root(/)directory.
 Many directories have children directories.
 Unlike Windows, with multiple drives and multiple file
systems, a *Nix system only has ONE file system.
 The Linux Standard Base (LSB) specifies the structure
of a Linux file system.
The Linux File System
A Typical Linux File System
root
The root user is the master
Types of Linux File System

◦ Disk file systems


◦ Network file systems
◦ Mounting file systems
Disk file systems
 Disk file systems takes advantages of the
ability of the disk storage media to randomly
address data in a short amount of time.

 This permits multiple users(or processes)


access to various data on the disk without
regard to the sequential location of the data.
Types of Disk File System
 Linux offers various file systems like the ones below
that you can select from:
 Ext
 Ext2
 Ext3
 Ext4
 JFS
 XFS
 btrfs
 swap
Ext2
 Ext2 stands for second extended file systems.
 Introduced in 1992, developed by Remy Card
 This was developed to overcome the

limitations of the original ext file system.


 Ext2 does not have journaling feature
 On flash drives, usb drives, ext2 is

recommended.
 Overall ext file system size can be from 2 TB

to 32 TB
Ext3
 Ext3 stands for third extended file systems.
 Introduced in 2001, developed by Stephen
Tweedie.
 Starting from Linux kernel 2.4.15 ext3 was
available
 The main benefits of Ext3 is that it allows
journaling
 Maximum individual file size can be from 16GB
to 2TB
 Overall ext3 file system size can be from 2 TB
to 32 TB
XFS
 Extent File System
 Created by Silicon Graphics to work as a 64-

bit journaling file system.


 It was originally made for OS “IRIX”, but later

given to Linux.
 It was designed to maintain high performance

with large files and file systems.


 It supports foreign file systems exists, to

make it easier to exchange files with other


operating systems.
Network File Systems
 A network file system is a file system that
acts as a client for a remote file access
protocol, providing access to files on a
server.
 Examples of network file systems include

clients for the NFS, AFS, SMB protocols.


Mounted File System
 The Linux file system makes it appear as if all
the File System are local and mounted
somewhere on the root File system.
 File system are mounted with the mount

command.
mount –t type source mount_point
To unmounts a file system
Unmount/div/<device name>or mount_point
Commands for navigating the Linux
file systems
 Pwd – shows the current location in the
directory tree.
 cd-change into specified directory name
 cd~ alias for your home directory
 Cd.. Move up one directory
 Cd- return to previous directory
The List Command
 Useful options for the “ls” command:
◦ ls -a List all file including hidden file beginning
with a period “.”
◦ ls -ld * List details about a directory and not its
contents
◦ ls -F Put an indicator character at the end of each
name
◦ ls –l Simple long listing
◦ ls –lh Give human readable file sizes
◦ ls –lS Sort files by file size
◦ ls –lt Sort files by modification time
File System Ownership and
Permissions
 All files and directories have a individual and
a group ownership.
 All files and directories have read (r), write

(w), and execute (x) permissions assigned as


octets to the individual owner (u), the group
(g) owner and all others (o) that are logged
into the system.
 You can change permissions if you are the

individual owner or a member of the group.


 Only root can change ownership.
LINUX SECURITY MODULE

 The Linux Security Module (LSM) framework


provides a mechanism for various security
checks to be hooked by new kernel extensions.
 The name “module” is a bit of a misnomer since
these extensions are not actually loadable
kernel modules.
 The primary users of the LSM interface are
Mandatory Access Control (MAC) extensions
which provide a comprehensive security policy.
Examples include SELinux, Smack, Tomoyo, and
AppArmor.
 AppArmor
 LoadPin
 SELinux
 Smack
 TOMOYO
 Yama
ViEditor
 The vi editor is elaborated as visual editor. It is
installed in every Unix system. In other words, it is
available in all Linux distros.
 It is user-friendly and works same on different
distros and platforms.
 It is a very powerful application. An improved
version of vi editor is vim.
 The vi editor has two modes:
 Command mode
 Insert mode
Using vi
 The vi editor tool is an interactive tool as it
displays changes made in the file on the
screen while you edit the file.
 In vi editor you can insert, edit or remove a
word as cursor moves throughout the file.
Commands are specified for each function like
to delete it's x or dd.
 The vi editor is case-sensitive. For example, p
allows you to paste after the current line while
P allows you to paste before the current line.
Vi syntax
 vi <fileName>

 In the terminal when you'll type vi command


with a file name, the terminal will get clear
and content of the file will be displayed.
 If there is no such file, then a new file will be

created and once completed file will be saved


with the mentioned file name.
Vi commands
 Linux vi editor is different from other editors.
You have to use different keys to use
different functions.
 Although, it's quite easy and interesting to

use vi editor. The vi editor commands are


case sensitive.
To switch from command to insert mode:

Command Action

i Start typing before the current character

I Start typing at the start of current line

a Start typing after the current character

A Start typing at the end of current line

o Start typing on a new line after the current line

O Start typing on a new line before the current line


To move around a file:

Commands Action

j To move down

k To move up

h To move left

l To move right
To jump lines:

Commands Action

G Will direct you at the last line of the file

`` Will direct you to your last position in the file


To delete:

x Delete the current character

X Delete the character before the cursor

r Replace the current character

xp Switch two characters

dd Delete the current line

D
Delete the current line from current character to the end of the l
To repeat and undo:

Commands Action

u Undo the last command

. Repeat the last command


Command to cut, copy and paste:

Commands Action

dd Delete a line

yy (yank yank) copy a line

p Paste after the current line

P Paste before the current line


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

Linux shell
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 –
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 –
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
Adv and disadv of shell scripts
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
◦ Interactive debugging etc.
Disadvantages of shell scripts
◦ Slow execution speed
◦ Not well suited for large and complex task
SHELL STRING PROCESSING
String Manipulation is defined as performing
several operations on a string resulting
change in its contents.
 In Shell Scripting, this can be done in two

ways:
i)pure bash string manipulation,
ii) string manipulation via external
commands.
Basics of pure bash string manipulation:

 Assigning content to a variable and printing


its content
 To print length of string inside Bash Shell
 Concatenate strings inside Bash Shell using

variables
 Concatenate strings inside Bash Shell using

an array
 Extract a substring from a string
INVESTIGATION AND PROCESS
MANAGEMENT:
 A process means program in execution. It
generally takes an input, processes it and
gives us the appropriate output.
 There are basically 2 types of processes.

i. Foreground processes
ii. Background processes
Example of foreground process
 Sleep 5
 Jobs
 Bg
 Ps-ef|grep sleep
 Fg
 Nohup sleep 100
 Nice-n5 sleep 100
 top
LINUX NETWORKING CLIENTS
 Every computer is connected to some other
computer through a network whether
internally or externally to exchange some
information. This network can be small as
some computers connected in your home or
office, or can be large or complicated as in
large University or the entire Internet.
 Maintaining a system's network is a task of

System/Network administrator. Their task


includes network configuration and
troubleshooting.
List of Networking and Troubleshooting
commands
ifconfig Display and manipulate route and network interfaces.

traceroute Network troubleshooting utility.

ping To check connectivity between two nodes.

netstat Display connection information.

dig Query DNS related information.

nslookup Find DNS related query.

route Shows and manipulate IP routing table.

host Performs DNS lookups.

iwconfig Used to configure wireless network interface.

hostname To identify a network name.

curl or wget To download a file from internet.

mtr Combines ping and tracepath into a single command.


Mission Possible: Editing Files with Emacs and Vim
• Someone has corrupted Edgar Allen Poe’s poem, “The Raven.” Your
mission, should you decide to accept it, is to repair the damage with
emacs or vim and then confirm with the “diff” command. Hint: Also
use diff to find corruption.

• emacs –nw bad-the-raven.txt


or
• vim bad-the-raven.txt

• After editing and saving your file, confirm you work with:
• diff bad-the-raven.txt good-the-raven.txt
Finis

You might also like