Uploaded by satyam1704gupta

LINUX LAB MANUAL

advertisement
PRACTICAL-1
OBJECT: STUDY OF LINUX OPERATING SYSTEM WITH ITS FEATURES.
An
operating
system (OS)
is
software
that
manages
computer
hardware and software resources and provides common services for computer
programs and provides you with the capability of communicating with your computer.
Operations of operating system-
Linux is multi-user operating system allows for multiple users to use the same
computer at the same time and/or different times.
Linux is a free Unix-type operating system originally created by Linus Torvalds
developed under the GNU General Public License and the source code of which is
freely available to everyone.
Various versions of Linux operating system SUSE
1
 FEDORA
 REDHAT
 DEBIAN
 UBANTU
 KNOPPIX
 SLACKWARE
Features of Linux Operating SystemPortable- Portability means software’s can works on different types of hardware’s in
same way. Linux kernel and application programs support their installation on any kind
of hardware platform.
Open Source- Linux open source code is freely available and it is community based
development project. Multiple teams’ works in collaboration to enhance the capability
of Linux operating system and it is continuously evolving.
Multiuser- Linux is multiuser system means multiple users can access system resources
like memory/RAM/ application programs at same time.
Multiprogramming- Linux is multiprogramming operating 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 interpret the
commands given by the user and then conveys them to the kernel which ultimately
executes the command.
Security- Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.
Communication- Linux has excellent provision for communicating with fellow users.
The communication may be within the network or between two or more such computer
networks. The users can easily exchange mail, data, and programs through such
networks.
2
PRACTICAL-2
OBJECT: STUDY OF LINUX OPERATING SYSTEM ARCHITECTURE.
Linux architecture is shown in the following figure-
When Linux is running in main memory, it is divided into two parts1. User space- User’s applications are running in user space.
2. Kernel space- Kernel is running in kernel space.
The system libraries(eg glibc) defines a standard set of functions through which
applications interact with the kernel, and which implement much of the operating system
functionality that does not need the full privileges of kernel code.
Linux architecture consists of –
1. Monolithic kernel - contains modular components.
2. Linux-based operating system.
3. Six primary subsystems:
Process management
Inter process communication
Memory management
File system management
I/O management
Networking
3
Linux kernel architecture is shown in the following figure-
4
PRACTICAL-3
OBJECT: STUDY THE DIFFERENCE BETWEEN WINDOWS AND LINUX
OPERATING SYSTEM.
WINDOWS OS
LINUX OS
It is a series of software operating systems
and graphical user interfaces produced by
Microsoft.
It is a free Unix-type operating system
originally created by Linus Torvalds
developed under the GNU General Public
License and the source code of which is
freely available to everyone.
Bundled software- by default it has very
minimal software set. The basic word
processor, spread sheet and presentation
software are not present. This MS office
suite needs to install separately.
Bundled software- Linux comes with the
Libre Office suite (a Microsoft Office
Equivalent) preinstalled.
Drivers- It is a big pain that comes when
completing a fresh install of Windows 7.
Drivers- LINUX- Biggest advantages of is
its built-in driver set.
Need to download all the drivers required
for all the software like webcam, Wi-Fi,
Ethernet Card, printer or scanner.
The ability of automatically downloading
and installing them. This includes the
drivers for your webcam, Wi-Fi, Ethernet
Card, even your printer or scanner
Price- As compared to linux the price of
windows is much higher. It can run
between $100 - $200 US per each license
copy.
Price- The majority of Linux variants are
available for free or at a much lower price
than Microsoft windows.
Reliability- Windows has made great
improvements in reliability over the last
few versions of windows it still can’t match
the reliability of Linux.
Reliability- The majority of Linux variants
and versions are notoriously reliable and
can often run for months and years without
needing to be rebooted.
Hardware- Because of the amount of
Microsoft Windows users and the broader
driver support, Windows has a much larger
support for hardware devices and almost all
HardwareAlthough
hardware
manufacturers
have
made
great
advancements in supporting Linux it still
It also has F-spot, an image editing
program that and an Instant messaging
client called Empathy – that has chat
provisioning for Facebook, G-Talk,
Yahoo,MSN and VOIP capabilities all
under a single application.
5
hardware manufacturers will support their
products in Microsoft Windows.
will not support most hardware devices.
Security- Microsoft has made great
improvements over the years with security
on their operating system; their operating
system continues to be the most vulnerable
to viruses and other attacks.
Security- Linux is and has always been a
very secure operating system. It still can be
attacked when compared to Windows; it is
much more secure than windows.
Open Source- Microsoft Windows is not
open source and the majority of Windows
programs are not open source.
Open Source- Many of the Linux variants
and many Linux programs are open source
and enable users to customize or modify the
code however they wish to.
Software cost- Although Windows does
have software programs, utilities, and
games for free, the majority of the
programs will cost anywhere between
$20.00 - $200.00+ US dollars per copy.
Software cost- Many of the available
software programs, utilities, and games
available on Linux are freeware or open
source.
For the hardware devices that have driver
support, they will usually work in all
versions of Linux.
Programs such as Gimp, Open Office, Star
Office, and wine are available for free or at
a low cost.
6
PRACTICAL-4
OBJECT: STUDY THE DIFFERENCE BETWEEN LINUX AND UNIX
OPERATING SYSTEM.
LINUX OS
UNIX OS
Free because open source.
Cost Money
Kernel (heart) of an OS. Only With a Linux
Distribution make a completely usable OS.
A Family of OS (eg. AIX, BSDI, Solaris,
SunOS). Vendors provide complete OS.
Open Source, fully customizable, can
change kernel and create ‘new’ OS.
Mostly come with A-Z programs, editors,
compilers, etc.
Most
Software
is
Open
Source,
compatibility issues can be rectified by
compiling for the relevant platform.
Software should be compatible with the
kind of UNIX installed.
User friendly for general computing.
Less user friendly.
Powerful
needed.
hardware
configuration
not
Powerful hardware configuration needed.
Less testing before release;
Vendors carryout testing before release;
New version less reliable.
New versions are almost always reliable.
Non formal technical support; no single
point of contact support.
Vendors provide technical support; Single
point of contact supported.
7
PRACTICAL-5
OBJECT: STUDY THE FILE SYSTEM OF LINUX OPERATING SYSTEM.
All utilities, applications, data in Linux are stored as files. Even a directory is treated as a
file which contains several other files. Thus, the file system begins with a directory called
“root”. The root directory is denoted by as slash (/). Branching from the root there are
several other directories. The basic structure of linux file system is shown in the following
figure.
/(root)
linux
bin
lib
user 1
usr
user 2
dev
user 3
tmp
etc
bin
These directories are called sub-directories, which further contain several files and
directories called sub-sub-directories. The brief description of these directories is shown in
the following table.
Directory
Contains
bin
Binary executable files.
lib
Library functions provided by the Linux for programmers.
usr
Home directories of all users
dev
Files that control various i/o devices like terminals, printer, disk drivers etc.
tmp
Temporary files created by Linux or users Home directories of all users.
etc
Binary executable files usually required for system administration.
/usr/bin
Additiona
8
PRACTICAL-6
OBJECT: STUDY AND USE OF BASIC LINUX COMMANDS.
LINUX Commands
Commands tell the operating system to perform set of operations.
The various commands are as followsCommand: man
The man command - the manual command - is used to show the manual of the
inputted command. example:
$man cd
Command: history
History command shows all the commands that you have used in the past for the
current terminal session. This can help you refer to the old commands you have
entered and re-used them in your operations again.
$history
Command: clear
to clear the screen.
$clear
Command: date
to see the system’s date.
$date
Command: time
to see the system’s time.
$time
Command: cal
It is used to see the calendar of any specific month, or a complete year.
$cal 11 2018
will show the calendar of Nov 2018.
Command: who
It is used to see the details of various users who are currently log in.
$who
Command: ps
It is used to see various process running at a terminal.
$ps
Command: pwd
It is used to see the present working directory.
$pwd
9
PRACTICAL-7
OBJECT: STUDY OF VARIOUS FILE MANAGEMENT COMMANDS IN
LINUX OS.
Command: cat
$ cat filename
It will display the contents of the file filename.
$cat >file1
Success is not a destination.
[Ctrl+d]
$
The above command creates the file called file1 and you can enter the text
there only. After finishing your work press Ctrl+d (Press Enter after the
last line of your character to denote the end of the file).
If file1 already exists then it over writes the contents of the file1.
”>” is called output redirection Operator.
$cat sample1 sample2 > newsample
The newsample file contains contents of sample1 followed by that of sample2. If
newsample already exists then it is overwritten.
$cat sample1 sample2 >> newsample
In this case newsample file is appened. The operator “>>” is called append output
redirection.
$cat sample1
cat command is also used to see the contents of sample1 file created by user.
Command: cp(copy)
Syntax $ cp [options] Source Destination
Copies Source into Destination
$ cp file1 file2
Copies file1 into file2
Command: mv
To move a file to different location use “mv”.
$ mv [options] Source Destination
mv can also be used to rename a file.
$ mv filename1 filename2 (Rename file)
Command: rm
To remove a file use “rm”.
Syntax: $ rm filename
10
PRACTICAL-8
OBJECT: Create A File Called Wlcc.Txt With Some Lines And Display How
Many Lines, Words And Characters Are Present In That File.
THEORY : Word count command Command: wc
$ wc[options] filename.
Gives the number of lines, words and characters in a file called filename
$wc –l filename
Gives the number of lines
$wc –w filename
Gives the number of words
$wc –c filename
Gives the number of characters
PROCEDURE : We will perform the practical in following steps :
STEP : 1). Create the file wlcc.txt using vi-editor :
a. vi wlcc.txt
b. Insert text using esc + i
Welcome to the world of Linux
c. Then save and quit after writing the text using esc + : + wq
STEP : 2). Go to the shell prompt and type command wc to view the number of
Lines, Words and Characters.
$ wc wlcc.txt
Note : Write output on blank page
11
PRACTICAL-9
OBJECT: Explain ls command and directory management commands.
Command: ls
To lists the files in the current directory use “ls”.
ls has many options:
-l long list (Displays lots of info)
-t lists by modification date
-S lists by size
-h lists file sizes in human readable format
-r Reverse the order
-a Lists all hidden files
$ls ?ain
When above command is executed it displays all the file names having last three
characters are “ain”, ignore the first char (? Replaces single char).
$ls s*
When above command is executed it displays all the files which begins character “s”,
ignore the rest of the characters(* replace multiple characters).
Command: mkdir(make directory)
To create a new directory use “mkdir”.
Syntax: $ mkdir directoryname
$mkdir –p dir1/dir2/dir3.
It will create the directory tree.dir3 will created under dir2 and dir2 is created under
dir1.
Command: cd (change directory)
cd dir_name
Moves to directory called dir_name
cd ~
Moves to your home directory
cd ..
Moves one level hierarchy down from the current directory
cd .. /../
Moves two level hierarchy down from the current directory
cd - Moves to your previous directory
Command: rmdir
To remove a empty directory use “rmdir”.
Syntax :$ rmdir directoryname
Command: pwd
To find your current path use “pwd”.
Syntax: $ pwd
Displays the present working directory
12
PRACTICAL-10
OBJECT: Study and use of the command for changing file permissions.
THEORY : File Permissions:
Each file in UNIX/LINUX has an associated permission level. This allows the user to
prevent others from reading/writing/executing their files or directories
Command “ls –l filename ” is used to find permission level of that file. The
permission levels are:
1. “r” means “read only” permission = (4)
2. “w” means “write” permission = (2)
3. “x” means “execute” permission = (1)
Command: change mode (chmod)
If you own a file, you can change its permissions with “chmod”.
Syntax:
$ chmod [user/group/others/all]+[permission] filename
Or
$ chmod 755 filename
User Group Other
Procedure :
1. Go to any terminal ( or $ prompt ) and type command ls –l
2. After the list of files and directories is displayed along with mode of
permission , now select any file.
3. Change the mode of permission of the selected file using following command
: $chmod 755 filename
4. Again type ls –l command and now the permission of the desired file is
changed.
In the diagram below, we see how the first portion of the listing is interpreted. It
consists of a character indicating the file type, followed by three sets of three
characters that convey the reading, writing and execution permission for the owner,
group, and everybody else.
13
chmod
The chmod command is used to change the permissions of a file or directory. To
use it, you specify the desired permission settings and the file or files that you
wish to modify. There are two ways to specify the permissions. In this lesson we
will focus on one of these, called the octal notation method.
It is easy to think of the permission settings as a series of bits (which is how the
computer thinks about them). Here's how it works:
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000
and so on...
rwx
rwr-x
r--
=
=
=
=
111
110
101
100
in
in
in
in
binary
binary
binary
binary
=
=
=
=
7
6
5
4
Value
Meaning
777
(rwxrwxrwx) No restrictions on permissions. Anybody may
do anything. Generally not a desirable setting.
755
(rwxr-xr-x) The file's owner may read, write, and execute the
file. All others may read and execute the file. This setting is
common for programs that are used by all users.
700
(rwx------) The file's owner may read, write, and execute the
14
file. Nobody else has any rights. This setting is useful for
programs that only the owner may use and must be kept
private from others.
666
(rw-rw-rw-) All users may read and write the file.
644
(rw-r--r--) The owner may read and write a file, while all
others may only read the file. A common setting for data files
that everybody may read, but only the owner may change.
600
(rw-------) The owner may read and write a file. All others
have no rights. A common setting for data files that the owner
wants to keep private.
Directory Permissions
The chmod command can also be used to control the access permissions for
directories. Again, we can use the octal notation to set permissions, but the meaning of
the r, w, and x attributes is different:



r - Allows the contents of the directory to be listed if the x attribute is also set.
w - Allows files within the directory to be created, deleted, or renamed if the x
attribute is also set.
x - Allows a directory to be entered (i.e. cd dir).
WRITE DOWN THE OUTPUT IN BLANK PAGE OF YOUR FILE
15
PRACTICAL-11
OBJECT: Study of vi editor.
THEORY : vi editor
vi is the most useful standard text editor on your system. (vi is
short for visual editor and is pronounced "vee-eye."). UNIX has a number of editors
that can process the contents of text files, whether those files contain data, source
code, or sentences. Editor (VI – editor) is screen editors which display a part of the
file on your terminal screen.
vi. This editor enable you to edit lines in context with other lines in the file.
Now a day you would find an improved version of vi editor which is called vi. Here
VIM stands for vi improved.
The VI is generally considered the de facto standard in UNIX editors because −
It's usually available on all the flavors of UNIX system. Its implementations are very
similar across the board. It requires very few resources.
You can use vi editor to edit an existing file or to create a new file from scratch. You
can also use this editor to just read a text file.
Starting the vi Editor
There are following way you can start using VI editor −
Command
Description
vi filename
Creates a new file if it already does not exist, otherwise opens
existing
file.
vi -R filename
Opens an existing file in read only mode.
view filename
Opens an existing file in read only mode.
Following is the example to create a new file testfile if it already does not exist in the current working
directory −
$vi testfile
As a result you would see a screen something like as follows −
16
|
~
~
~
~
~
~
~
~
~
~
~
~
"testfile" [New File]
You will notice a tilde on each line following the cursor. A tilde represents an unused line. If a line does
not begin with a tilde and appears to be blank, there is a space, tab, newline, or some other
nonviewable character present.
17
So now you have opened one file to start with. Before proceeding further let us understanding few
minor but important concepts explained below.
Operation Modes
While working with vi editor you would come across following two modes −
Command mode − This mode enables you to perform administrative tasks such as saving files,
executing commands, moving the cursor, cutting yanking and pasting lines or words, and finding and
replacing. In this mode, whatever you type is interpreted as a command.
Insert mode − This mode enables you to insert text into the file. Everything that's typed in this
mode is interpreted as input and finally it is put in the file .
The vi always starts in command mode. To enter text, you must be in insert mode. To come in insert
mode you simply type i. To get out of insert mode, press the Esc key, which will put you back into
command mode.
Hint − If you are not sure which mode you are in, press the Esc key twice, and then you'll be in
command mode. You open a file using vi editor and start type some characters and then come in
command mode to understand the difference.
Getting Out of vi
The command to quit out of vi is :q. Once in command mode, type colon, and 'q', followed by return.
If your file has been modified in any way, the editor will warn you of this, and not let you quit. To
ignore this message, the command to quit out of vi without saving is :q!. This lets you exit vi without
saving any of the changes.
The command to save the contents of the editor is :w. You can combine the above command with the
quit command, or :wq and return.
The easiest way to save your changes and exit out of vi is the ZZ command. When you are in
command mode, type ZZ and it will do the equivalent of :wq.
You can specify a different file name to save to by specifying the name after the :w. For example, if
you wanted to save the file you were working as another filename called filename2, you would type
:w filename2 and return. Try it once.
Moving within a File
To move around within a file without affecting your text, you must be in command mode press Esc
twice. Here are some of the commands you can use to move around one character at a time
Command
Description
K
Moves the cursor up one line.
J
Moves the cursor down one line.
H
Moves the cursor to the left one character position.
L
Moves the cursor to the right one character
position.
There are following two important points to be noted −
The vi is case-sensitive, so you need to pay special attention to capitalization when using
commands.
Most commands in vi can be prefaced by the number of times you want the action to occur. For
example, 2j moves cursor two lines down the cursor location.
There are many other ways to move within a file in vi. Remember that you must be in command
mode pressEsctwice. Here are some more commands you can use to move around the file −
Command
Description
0 or |
Positions cursor at beginning of line.
$
Positions cursor at end of line.
W
Positions cursor to the next word.
B
Positions cursor to previous word.
(
Positions cursor to beginning of current sentence.
)
Positions cursor to beginning of next sentence.
E
Move to the end of Blank delimited word
{
Move a paragraph back
}
Move a paragraph forward
[[
Move a section back
]]
Move a section forward
n|
Moves to the column n in the current line
1G
Move to the first line of the file
G
Move to the last line of the file
nG
Move to nth line of the file
:n
Move to nth line of the file
Fc
Move forward to c
Fc
Move back to c
H
Move to top of screen
nH
Moves to nth line from the top of the screen
M
Move to middle of screen
L
Move to bottom of screen
nL
Moves to nth line from the bottom of the screen
:x
Colon followed by a number would position the cursor on line number
represented by x
Editing Files
To edit the file, you need to be in the insert mode. There are many ways to enter insert mode from
the command mode −
Command
Description
I
Inserts text before current cursor location.
I
Inserts text at beginning of current line.
A
Inserts text after current cursor location.
A
Inserts text at end of current line.
O
Creates a new line for text entry below cursor location.
O
Creates a new line for text entry above cursor
location.
Deleting Characters
Here is the list of important commands which can be used to delete characters and lines in an opened file
Command
Description
X
Deletes the character under the cursor location.
X
Deletes the character before the cursor location.
Dw
Deletes from the current cursor location to the next word.
d^
Deletes from current cursor position to the beginning of the
line.
d$
Deletes from current cursor position to the end of the line.
D
Deletes from the cursor position to the end of the current line.
Dd
Deletes the line the cursor is on.
As mentioned above, most commands in vi can be prefaced by the number of times you want the
action to occur. For example, 2x deletes two character under the cursor location and 2dd deletes
two lines the cursor is on.
Copy and Past Commands
You can copy lines or words from one place and then you can past them at another place using
following commands −
Command
Description
Yy
Copies the current line.
Yw
Copies the current word from the character the lowercase w cursor is
on until the end of the word.
P
Puts the copied text after the cursor.
P
Puts the yanked text before the cursor.
PRACTICAL-12
OBJECT: Study of Linux shell and operators used in it.
SHELL:
Shell interprets the commands from the user and translate them to understandable by
kernel.
SHELL SCRIPT:
Shell script is a file which stores the series of commands. Shell will execute this text file
instead of entering the commands.
The shell provides you with an interface to the UNIX system. It gathers input from you
and executes programs based on that input. When a program finishes executing, it
displays that program's output.
A shell is an environment in which we can run our commands, programs, and shell
scripts. There are different flavors of shells, just as there are different flavors of
operating systems. Each flavor of shell has its own set of recognized commands and
functions.
Shell Prompt
The prompt, $, which is called command prompt, is issued by the shell. While the
prompt is displayed, you can type a command.
The shell reads your input after you press Enter. It determines the command you want
executed by looking at the first word of your input. A word is an unbroken set of
characters. Spaces and tabs separate words.
Following is a simple example of date command which displays current date and time:
$date
Thu Jun 25 08:30:19 MST 2006
Shell Types
In UNIX there are two major types of shells:

The Bourne shell. If you are using a Bourne-type shell, the default prompt is the $
character.

The C shell. If you are using a C-type shell, the default prompt is the % character.
There are again various subcategories for Bourne Shell which are listed as follows

Bourne shell ( sh)

Korn shell ( ksh)

Bourne Again shell ( bash)

POSIX shell ( sh)
The different C-type shells follow −

C shell ( csh)

TENEX/TOPS C shell ( tcsh)
The original UNIX shell was written in the mid-1970s by Stephen R. Bourne while he
was at AT&T Bell Labs in New Jersey.
The Bourne shell was the first shell to appear on UNIX systems, thus it is referred to as
"the shell".
The Bourne shell is usually installed as /bin/sh on most versions of UNIX. For this
reason, it is the shell of choice for writing scripts to use on several different versions of
UNIX.
There are various operators supported by each shell. Our tutorial is based on
default shell (Bourne) so we are going to cover all the important Bourne Shell
operators in the tutorial.
There are following operators which we are going to discuss −

Arithmetic Operators.

Relational Operators.

Boolean Operators.

String Operators.

File Test Operators.
The Bourne shell didn't originally have any mechanism to perform simple
arithmetic but it uses external programs, either awk or the must simpler
program expr.
Here is simple example to add two numbers −
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
This would produce following result −
Total value : 4
There are following points to note down −

There must be spaces between operators and expressions for example 2+2
is not correct, where as it should be written as 2 + 2.

Complete expression should be enclosed between ``, called inverted
commas.



There are following arithmetic operators supported by Bourne Shell.
Assume variable a holds 10 and variable b holds 20 then −
Show Examples
Operat
or
Description
Example
+
Addition - Adds values on either
side of the operator
`expr $a + $b` will give
30
-
Subtraction - Subtracts right hand
operand from left hand operand
`expr $a - $b` will give
-10
*
Multiplication - Multiplies values on
either side of the operator
`expr $a \* $b` will
give 200
/
Division - Divides left hand
operand by right hand operand
`expr $b / $a` will give
2
%
Modulus - Divides left hand
operand by right hand operand
`expr $b % $a` will
give 0
and returns remainder
=
Assignment - Assign right operand
in left operand
a=$b
would
value of b into a
==
Equality - Compares two numbers,
if both are same then returns true.
[ $a == $b ] would
return false.
!=
Not Equality - Compares two
numbers, if both are different then
returns true.
[ $a != $b ] would
return true.
assign
Bourne Shell supports following relational operators which are specific to numeric
values. These operators would not work for string values unless their value is
numeric.
For example, following operators would work to check a relation between 10 and
20 as well as in between "10" and "20" but not in between "ten" and "twenty".
Operator
Description
Example
-eq
Checks if the value of two
operands are equal or not, if yes
then condition becomes true.
[ $a -eq $b ] is
not true.
-ne
Checks if the value of two
operands are equal or not, if
values are not equal then
condition becomes true.
[ $a -ne $b ] is
true.
-gt
Checks if the value of left operand
is greater than the value of right
operand, if yes then condition
becomes true.
[ $a -gt $b ] is
not true.
-lt
Checks if the value of left operand
is less than the value of right
operand, if yes then condition
becomes true.
[ $a -lt $b ] is
true.
-ge
Checks if the value of left operand
is greater than or equal to the
value of right operand, if yes then
condition becomes true.
[ $a -ge $b ] is
not true.
-le
Checks if the value of left operand
is less than or equal to the value
of right operand, if yes then
condition becomes true.
[ $a -le $b ] is
true.
PRACTICAL-13
OBJECT: Write shell script to explain “if” command .
if script:
#!/bin/sh
echo -n "enter the key : "
read key
if [ $key -eq 1122 ]
then
echo "you entered correct key"
fi
output:
enter the key : 1122
you entered correct key
if else script:
#!/bin/sh
echo -n "enter the key : "
read key
if [ $key -eq 1122 ]
then
echo "you entered correct key"
else
echo "you entered wrong key"
fi
output:
i)
enter the key : 100
you entered wrong key
ii)
enter the key : 1122
you entered correct key
nested if:
#!/bin/sh
echo "1. windows"
echo "2. Linux "
echo -n "which operating you like to work 1 or 2 ? "
read sel
if [ $sel -eq 1 ]
then
echo "you selected windows"
else
if [ $sel -eq 2 ]
then
echo "you selected linux"
else
echo "wrong selection select 1 or 2"
fi
fi
output:
i)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 1
you selected windows
ii)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 2
you selected linux
iii)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 3
wrong selection select 1 or 2
PRACTICAL-14
OBJECT: Write shell script to add two numbers.
echo “enter first number”
read a
echo “enter second number”
read b
c= expr $a + $b
echo “sum= $c”
ctrl+d
Output:
Enter first number 10
Enter second number 20
Sum=30
PRACTICAL-15
OBJECT: Write shell script to find maximum of two numbers.
echo “enter first number”
read a
echo “enter second number”
read b
if test $a –gt $b then
echo “$a is maximum”
else
echo “$b is maximum”
fi
ctrl+d
Output:
Enter first number 10
Enter second number 20
20 is maximum
Enter first number 100
Enter second number 20
100 is maximum
PRACTICAL-16
OBJECT: Write shell script to swap two numbers.
echo “enter first number”
read a
echo “enter second number”
read b
echo “Before swapping”
echo “a= $a”
echo “b= $b”
$t = $a
$a = $b
$b = $t
echo “After swapping”
echo “a= $a”
echo “b= $b”
Output:
Enter first number 100
Enter second number 200
Before swapping
a = 100
b = 200
After swapping
a = 200
b = 100
PRACTICAL-17
OBJECT: Write shell script to illustrate for and while loop.
for loop will execute the loop again and again, until particular condition is true.
script:
for var in 1 2 3 4 5
do
echo "loop $var"
done
output:
loop 0
loop 1
loop 2
loop 3
loop 4
loop 5
While will execute the loop as long as condition true.
When condition meet false it will terminate from the loop.
Script:
var=1
while [ $var -le 5 ]
do
echo "Loop $var"
(( var++ ))
done
output:
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5
VIVA-VOCE
1. What is operating system?
2. What are the features of operating system.
3. What are the features of Linux OS.
4. Define shell.
5. Define kernel.
6. What are the names of shell in Linux OS.
7. What is process?
8. Why cat command is used?
9. What is meant by security in Linux OS?
10.Explain about tty, who, cat, ps, kill commands.
11.File management commands in Linux.
12.Directory management commands in Linux.
13.Explain in brief file system in Linux OS.
14.What is vi editor?
15.How many modes in which vi editor is working?
16.What is shell script?
17.Explain relational operators used in shell programming.
18.Explain chmod command.
19.Explain shell variables.
20.Explain branching and looping in shell programming.
THE END
Download
Study collections