Os Lab-Mayur
Os Lab-Mayur
TECHNOLOGY
BACHELOR OF TECHNOLOGY
4TH SEM
CERTIFICATE
Date of Submission:.........................
Staff In charge:...........................
Head of Department:..........................................
1
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
TABLE OF CONTENTS
2
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
PRACTICAL 1
DESCRIPTION:
SYNTAX:
Pwd
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
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
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:
2. The C shell: The prompt for this shell is %, and its subcategories are:
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.
1. Create a file using a vi editor(or any other editor). Name script file with extension
.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
#!/bin/sh
ls
11
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
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,
13
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
14
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
#Output:-
15
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
read b
c=$(($a/$b))
echo $c
#Output:-
16
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
#Output:-
#Output:-
17
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
#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
20
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
#Output:-
PRACTICAL 6
21
FACULTY OF ENGINEERING &
TECHNOLOGY,OS(203105214),B.TECH
ERP:-210303126039
#Output:-
22