0% found this document useful (0 votes)
97 views23 pages

Os Lab-Mayur

The document provides information about operating system laboratory experiments for a Bachelor of Technology course. It includes a certificate confirming completion of OS lab experiments, a table of contents listing the experiments performed, and details about the first two experiments - studying basic Linux commands and the basics of shell programming. The first experiment describes important commands like pwd, cd, ls, cat, head, tail, mv, mkdir, cp, rmdir, gedit, man, echo, clear, whoami, wc, grep, free and pipes. The second experiment defines what a shell is, the main shell types like Bourne and C shells, and introduces shell scripting.

Uploaded by

vicky krr
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)
97 views23 pages

Os Lab-Mayur

The document provides information about operating system laboratory experiments for a Bachelor of Technology course. It includes a certificate confirming completion of OS lab experiments, a table of contents listing the experiments performed, and details about the first two experiments - studying basic Linux commands and the basics of shell programming. The first experiment describes important commands like pwd, cd, ls, cat, head, tail, mv, mkdir, cp, rmdir, gedit, man, echo, clear, whoami, wc, grep, free and pipes. The second experiment defines what a shell is, the main shell types like Bourne and C shells, and introduces shell scripting.

Uploaded by

vicky krr
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/ 23

OS LAB MANUAL

FACULTY OF ENGINEERING AND

TECHNOLOGY

BACHELOR OF TECHNOLOGY

OPERATING SYSTEM LABORATORY (203105214)

4TH SEM

COMPUTER SCIENCE ENGINEERING TECHNOLOGY


FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

CERTIFICATE

This is to certify that

Mr./Ms MAYURKUMAR SANJAYBHAI PANDYA , Enrolment No

201303126039, has successfully Completed his/her laboratory

experiments in the OPERATING SYSTEM (203105214)

from the department of CSE-CS during The academic year 2022-23

Date of Submission:.........................

Staff In charge:...........................

Head of Department:..........................................

1
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

TABLE OF CONTENTS

Sr. Experiment Title Page No Date of Date of Sign Mar


No Performance Assessment ks
From To (out
of
10)

1 Study of Basic commands of Linux. 3 8

2 Study the basics of shell 9 18


programming.

3 Write a Shell script to print the 18 19


given numbers sum of all digits.

4 Write a shell script to validate the 19 20


entered date. (eg. Date format is:
dd-mm-yyyy).

5 Write a shell script to check if the 20 21


entered string is palindrome or not.

6 .Write a Shell script to say Good 21 22


morning/Afternoon/Evening as you
log in to the system.

2
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

PRACTICAL 1

AIM:-Study of Basic commands of Linux.

BASIC LINUX COMMANDS:

1) Pwd : print working directory

DESCRIPTION:

pwd prints the full pathname of the current working directory.

SYNTAX:
Pwd

2) cd: Change Directory


DESCRIPTION:
It allows you to change your working directory. You use it to move around within
the hierarchy of your file system.
SYNTAX:
cd directory_name
3) cd ..
DESCRIPTION:
Move up one directory.
SYNTAX:
cd ..
4) ls : list all the files and directories
DESCRIPTION:
List all files and folders in the current directory in the column format.
SYNTAX:
ls [options]

3
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

5) cat
DESCRIPTION:
cat stands for "catenate". It reads data from files, and outputs their contents. It is the
simplest way to display the contents of a file at the command line.
SYNTAX:
cat filename
6) head
DESCRIPTION:
head, by default, prints the first 10 lines of each FILE to standard output. With more than
one FILE, it precedes each set of output with a header identifying the file name.
If no FILE is specified, or when FILE is specified as a dash ("-"), head reads from
standard input.
SYNTAX:
head [option]...[file/directory]
7) Tail
DESCRIPTION:

tail is a command which prints the last few number of lines (10 lines by default) of a
certain file, then terminates.

SYNTAX:

tail [option]...[file/directory]
8) mv : Moving (and Renaming) Files
DESCRIPTION:
The mv command lets you move a file from one directory location to another. It also lets
you rename a file (there is no separate rename command).
SYNTAX:
mv [option] source directory

4
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

9) mkdir : Make Directory


DESCRIPTION:
If the specified directory does not already exist, mkdir creates it. More than one directory
may be specified when calling mkdir.
SYNTAX:
mkdir [option] directory
10) cp : Copy Files
DESCRIPTION:
The cp command is used to make copy of files and directories.
SYNTAX:
cp [option] source directory
11) rmdir : Remove Directory
DESCRIPTION:
The rmdir command is used to remove a directory that contains other files or directories.
SYNTAX:
rm directory_name
12) gedit
DESCRIPTION:
The gedit command is used to create and open a file.
SYNTAX:
13) man
DESCRIPTION:
Displays on an online manual page or manpage.
SYNTAX:
man command
14) echo
DESCRIPTION:
Display text on the screen.

5
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

SYNTAX:
echo yourtext
15) clear
DESCRIPTION:
Used to clear the screen
SYNTAX:
Clear
16) whoami
DESCRIPTION:
whoami prints the effective user ID. This command prints the username associated with
the current effective user ID.
SYNTAX:
whoami [option]
17) wc
DESCRIPTION:
wc (word count) command, can return the number of lines, words, and characters in a
file.
SYNTAX:
wc [option]... [file]...
18) grep
DESCRIPTION:
grep command uses a search term to look through a file.
SYNTAX:
grep [option]... Pattern [file]...
19) free
DESCRIPTION:
Display RAM details in Linux machine.
SYNTAX: Free

6
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

20) pipe ( | )
DESCRIPTION:
Pipe command is used to send output of one program as a input to another. Pipes “|” help
combine 2 or more commands.
SYNTAX:
Command 1 | command 2

OUTPUTES:-

7
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

8
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

PRACTICAL 2

AIM:-Study the basics of shell programming.

What is a Shell?
An Operating is made of many components, but its two prime components are -
• Kernel
• Shell

A Kernel is at the nucleus of a computer. It makes the communication between the hardware and
software possible. While the Kernel is the innermost part of an operating system, a shell is the
outermost one.
A shell in a Linux operating system takes input from you in the form of commands, processes it,
and
then gives an output. It is the interface through which a user works on the programs, commands,
and
scripts. A shell is accessed by a terminal which runs it.
When you run the terminal, the Shell issues a command prompt (usually $), where you can type

9
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

your input, which is then executed when you hit the Enter key. The output or the result is
thereafter
displayed on the terminal.
The Shell wraps around the delicate interior of an Operating system protecting it from accidental
damage. Hence the name Shell.
Types of Shell
There are two main shells in Linux:
1. The Bourne Shell: The prompt for this shell is $ and its derivatives are listed below:

● POSIX shell also is known as sh


● Korn Shell also knew as sh
● Bourne Again SHell also knew as bash (most popular)

2. The C shell: The prompt for this shell is %, and its subcategories are:

• C shell also is known as csh


• Tops C shell also is known as tcsh

What is Shell Scripting?

Shell scripting is writing a series of command for the shell to execute. It can combine lengthy
and repetitive sequences of commands into a single and simple script, which can be stored and
executed anytime. This reduces the effort required by the end user.

Let us understand the steps in creating a Shell Script

1. Create a file using a vi editor(or any other editor). Name script file with extension
.sh

2. Start the script with #! /bin/sh

3. Write some code.


4. Save the script file as filename.sh
5. For executing the script type bash filename.sh

"#!" is an operator called shebang which directs the script to the interpreter location. So, if we
use"#! /bin/sh" the script gets directed to the bourne-shell.

10
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

Let's create a small script -

#!/bin/sh
ls

Let's see the steps to create it –

Command 'ls' is executed when we execute the scrip sample.sh file.


Adding shell comments
Commenting is important in any program. In Shell programming, the syntax to add a comment is
#comment
Let understand this with an example.

11
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

What are Shell Variables?


As discussed earlier, Variables store data in the form of characters and numbers. Similarly, Shell
variables are used to store information and they can by the shell only.
For example, the following creates a shell variable and then prints it:
variable ="Hello"
echo $variable
Below is a small script which will use a variable.
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"
Let's understand, the steps to create and execute the script

12
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

As you see, the program picked the value of the variable 'name' as Joy and 'remark' as excellent.
This is a simple script. You can develop advanced scripts which contain conditional statements,
loops, and functions. Shell scripting will make your life easy and Linux administration a breeze.

Summary:
• Kernel is the nucleus of the operating systems, and it communicates between hardware and
software
• Shell is a program which interprets user commands through CLI like Terminal
• The Bourne shell and the C shell are the most used shells in Linux
• Shell scripting is writing a series of command for the shell to execute
• Shell variables store the value of a string or a number for the shell to read
• Shell scripting can help you create complex programs containing conditional statements,

loops, and functions

13
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

# Aim: - Write a shell script to make addition of two Numbers


# Input: -
#!/bin/bash
echo " Write a Program to Addition Of two Number "
echo " Enter the First Number"
read a
echo " Enter the second Number "
read b
c=$(($a+$b))
echo $c
#Output:-

# Aim: - Write a shell script to make subtraction of two Numbers


# Input: -
#!/bin/bash
echo " Write a Program to subtraction of two Number "
echo " Enter the First Number"
read a
echo " Enter the second Number "
read b
c=$(($a-$b))
echo $c

14
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

# Aim: - Write a shell script to make multiplication of two Numbers


# Input: -
#!/bin/bash
echo " Write a Program to multiplication of two Number "
echo " Enter the First Number"
read a
echo " Enter the second Number "
read b
c=$(($a*$b))
echo $c
#Output:-

# Aim: - Write a shell script to make division of two Numbers


# Input: -
#!/bin/bash
echo " Write a Program to do division of two Number "
echo " Enter the First Number"
read a
echo " Enter the second Number "

15
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

read b
c=$(($a/$b))
echo $c
#Output:-

# Aim: - Write a shell script to make modulus of two Numbers


# Input: -
#!/bin/bash
echo " Write a Program to find modulus of two numbers "
echo " Enter the First Number"
read a
echo " Enter the second Number "
read b
c=$(($a%$b))
echo $c
#Output:-

# Aim: - Write a shell script to type name


# Input: -
#!/bin/bash
echo " Enter Your Name "
read name
echo "Your name is "$name

16
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

# Aim: - Write a shell script to find swap of 2 numbers


# Input: -
#!/bin/bash
echo "Enter the First Number"
read first
echo "Enter the Second Number"
read second
temp=$first
first=$second
second=$temp
echo "After swapping, numbers are:"
echo "first = $first, second = $second"

#Output:-

# Aim: - Write a shell script to define variable


# Input: -
#!/bin/bash

17
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

echo " What is your name?"


read MY_NAME
echo " Hello, I'm "$MY_NAME". I Hope you are well"

#Output:-

PRACTICAL 3

AIM:-Write a Shell script to print the given numbers sum of all digits.
# Input: -
#!/bin/bash
echo "Enter a number"
read num
sum=0
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done
echo $sum

18
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

PRACTICAL 4

AIM:-Write a shell script to validate the entered date. (eg. Date format is:
dd-mm-yyyy).
# Input: -
#!/bin/bash
d=`date +%m-%d-%Y`
echo $d #DD-MM-YYYY
echo " Please Enter Date "
read D
echo " Please Enter Month "
read M
echo " Please Enter Year "
read Y
if [ `expr $Y % 4` -eq 0 ]
then
Mayur Pandya Division: - 4B18
echo "$Y is a leap year"
else
echo "$Y is not a leap year"
fi

19
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

PRACTICAL 5

AIM:-.Write a shell script to check entered string is palindrome or not


# Input: -
#!/bin/bash
# Store the string entered by the user
echo -n "Enter a string: "
read str
# Reverse the string
revstr=$(echo $str | rev)
# Check if the string is a palindrome
if [ "$str" == "$revstr" ]
then
echo "The string is a palindrome"
else
echo "The string is not a palindrome"
fi

20
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

PRACTICAL 6

AIM:-.Write a Shell script to say Good morning/Afternoon/Evening as you log in


to the system.
# Input: -
#!/bin/bash
# Get the current hour
hour=$(date +%H)
name=" Mayur Pandya "
# Set the greeting message
if [ $hour -ge 6 ] && [ $hour -lt 12 ]; then
greeting="Good morning $name"
elif [ $hour -ge 12 ] && [ $hour -lt 16 ]; then
greeting="Good afternoon $name"
elif [ $hour -ge 16 ] && [ $hour -lt 20 ]; then
greeting="Good evening $name"
else
greeting="Good Night $name"
fi
# Print the greeting message
echo $greeting

21
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039

#Output:-

22

You might also like