Você está na página 1de 21

UNIVERSITY OF MUMBAI

INSTITUTE OF DISTANCE AND OPEN LEARNING (IDOL) *


*(Institute

Of Distance Education (IDE) is renamed)

CERTIFICATE
THE EXPERIMENTS DULY SIGNED IN THIS JOURNAL REPRESENT
THE BONIFIED WORK BY MR.
ROLL NO.
IN SEMESTER II OF FIRST YEAR OF MASTER IN
COMPUTER APPLICATION (MCA) IN THE COMPUTER LABORATORY
OF PCP CENTER SHREE RAM COLLEGE, BHANDUP FOR SUBJECT
OPERATING SYSTEM DURING ACADEMIC YEAR 2013-14.

LECTURE IN CHARGE

HEAD OF DEPARTMENT OF MCA

EXTERNAL EXAMINER

OPERATING SYSTEM
INDEX
SR NO.

CONTENT

1.

Study of basic commands of linux

2.

Study of advanced command of linux

3.

Bash Shell to rename the file with change


in Suffix

4.

GCC & G++ Compiler program to find


factorial of the number

5.

GCC & G++ Compiler program to find


whether the number is prime or not

6.

Write menu-driven program to display


calendar, date, time, username, name of
the user displayed on x & y Co-ordinates
& terminal number.

7.

Write a Shell script to check whether the


string is palindrome or not

8.

Write a Shell Script to validate an entered


date

9.

Write the shell script to calculate area of


circle, rectangle, Square & triangle.

10.

To Generate mark Sheet using file


handling

11.

To Write a script which accept 2 string,


find the length of string, concatenate both
the string & print the string in reverse.

SIGNATURE

Practical No. :1
Aim: To Study basic commands of Linux
$who
User

ttyl1

Apr 15 11:47

$who am i
User

ttyl1

Apr 15 11:47

$pwd
/home/user
$tty
/dev/tty10
$uname
UWIN-NT
$uname -a
UWIN-NT user-0294fee (22062001)-5.12600 2600 il586
$uname -p
I386
$uname -r
(22062001)-5.12600
$uname -help
Uname: -h: unknown option
Uname: -e: unknown option
Usage: uname [-ailmnprsv][-S name]
$factor 15
-ksh: factor: notfound [No such file or directory]
$bc
Bc 1.04
Copyright (C) 1991,1992,1994,1997 Free Software Foundation, Inc.
This is Free Software with ABSOLUTELY NO WARRANTY.
For fetails type warranty.
/*Division*/
10/2
5
10.0/2
5
10/2.5
4
/*Multiplication*/

85*2
170
/*Square root*/
Sqrt(121)
11
/*Addition*/
2.5+2.5
5.0
/*Loop*/
For(i=5;i<=60;i=+2)i
(Standard_in)
For(i=1;i<=20;i=+2)i
1
3
5
7
9
11
13
15
17
19
Quit
(standard_ins) 15: illegal character: Q
$ cal
April 2011
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
$ date
Sat Apr 16 11:11:32 IST 2011
$ cat > newfile
My name is Abc
I am a IDE student
My roll no is 123
$ cat newfile
My name is Abc
I am a IDE student
My roll no is 123

$ ls -l
total 3600
-rw-r--r-- 1 user

None

52 Apr 16 11:12 newfile

$ touch
Usage: touch [-ancfmv] [-r file] [-t|d time] [ date ] file ...
$ mkdir newdir
$ cd newdir

Practical No. :2
Aim : To study advanced commands of Linux
$ tree
-ksh: tree: not found [No such file or directory]
$ alias p='ping'
$ p 192.168.1.2
Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
Ping statistics for 192.168.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
$ cat > AtoH
H
B
E
A
C
D
$ cat AtoH
H
B
E
A
C
D
$ sort AtoH
A
B
C

D
E
H
$ grep A newfile
My name is Abc
$ grep s newfile
My name is Abc
I am a IDE student
My roll no is 123
$ grep a newfile
My name is Abc
I am a IDE student
$ grep Abc newfile
My name is Abc
$ grep My newfile
My name is Abc
My roll no is 123
$ du
1
./newdir
10
$ cat > emp.lst
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800
$ sed -n '1,2p' emp.lst
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800
$ sed -n '1,2w temp' emp.lst
$ cat temp
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800

Practical No. :3
Aim: Bash shell to rename the file which change in the suffix
$ ls -ltr
total 5
-rw-r--r-- 1 user
-rw-r--r-- 1 user
-rw-r--r-- 1 user
drwxr-xr-x 2 user
-rw-r--r-- 1 user

None
None
None
None
None

174 Apr 16 11:48 emp.lst


104 Apr 16 11:51 newfile
12 Apr 16 11:52 AtoH
512 Apr 16 11:53 newdir
174 Apr 16 11:54 temp

$ for file in *.lst; do


> ln=`basename $file .lst`
> mv $file $ln.txt
> done
$ ls -ltr
total 5
-rw-r--r-- 1 user
-rw-r--r-- 1 user
-rw-r--r-- 1 user
drwxr-xr-x 2 user
-rw-r--r-- 1 user

None
None
None
None
None

174 Apr 16 11:48 emp.txt


104 Apr 16 11:51 newfile
12 Apr 16 11:52 AtoH
512 Apr 16 11:53 newdir
174 Apr 16 11:54 temp

Practical No. :4
Aim : gcc and g++ compiler program to find factorial of a number
$ cat > factorial.c
#include<stdio.h>
int main()
{
int n,fact,i;
fact=1;
printf("Enter the no.");
scanf("%d",&n);
for(i=n;i>0;i--)
{
fact=fact*i;
}
printf("\nFactorial of %d is %d\n',n,fact);
return 0;
}

Output:
gcc factorial.c
./a.out
Enter the no. 5
Factorial of 5 is 120

Practical No. :5
Aim : gcc and g++ compiler program to find whether a number is prime or not.
$ cat > factorial.c
#include<stdio.h>
int main()
{
int n,i;
printf("Enter the no.");
if(n==0)
{
printf("\nNumber is zero");
exit(0);
}
if(n==1||n==2)
{
printf("\n%d is prime number",n);
}
else
{
for(i=3;i<=n;i++)
{
if(n%i==0)
{
printf("\n%d is not a prime number\n",n);
exit(0);
}
}
printf("\n%d is a prime number\n",n);
}
return 0;
}

Output:
$ gcc primenum.c
$ ./a.out
Enter the no. 5
5 is a prime number
$ ./a.out
Enter the no. 6
5 is not a prime number

Practical No. :6
Aim : Write a menu-driven program to display calendar, date , time , username,
name of the user displayed on x & y co-ordinates & terminal number.
$ cat > menu.sh
#!/bin/bash
echo "Your choice"
choice=1
while test $choice -ne 0
do
echo "choices are:"
echo "1. Print Calendar"
echo "2. Print date"
echo "3. Print username"
echo "4. Terminal Number"
echo "0. Exit"
echo "Enter your choice:"
read choice
case $choice in
1) date;;
2) cal;;
3) who;;
4) tty;;
0) exit;;
*) echo "invalid input"
esac
done
Output:
$ sh menu.sh
Your choice
choices are:
1. Print Calendar
2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
1
Sat Apr 16 12:49:41 IST 2011
choices are:
1. Print Calendar

2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
2
April 2011
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
choices are:
1. Print Calendar
2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
3
user
tty11 Apr 16 11:47
choices are:
1. Print Calendar
2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
4
/dev/tty11
choices are:
1. Print Calendar
2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
0

Practical No. :7
Aim : Write a shell script to check whether the string is palindrome or not.
#!/bin/bash
echo "Enter a string"
read str
newstr=""
z=`echo $str|wc -m`
while [ $z -gt 0 ]
do
z=`expr $z - 1`
ch=`echo $str | cut -c $z`
newstr=$newstr$ch
done
if [ $str = $newstr ] ; then
echo $str is a palindrome
else
echo $str is not a palindrome
fi
Output:
$ sh palindrome
Enter a string
madam
madam is a palindrome
$ sh palindrome
Enter a string
adam
adam is not a palindrome

Practical No. :8
Aim: Write a shell script to validate an entered date
$ cat > valid.sh
#!/bin/bash
echo "Enter the date to validate"
echo "DD"
read dd
echo "MM"
read mm
echo "YYYY"
read yyyy
if [ $dd -gt 31 ] ; then
echo "Invalid date"
elif [ $mm -gt 12 -o $yyyy -le 0 ]
then
echo "Invalid month"
elif [ $yyyy -gt 9999 -o $yyyy -le 999 ]
then
echo "Invalid year"
else
echo "Your date is valid"
echo "$dd/$mm/$yyyy"
fi
Output:
$ sh valid.sh
Enter the date to validate
DD
06
MM
01
YYYY
1989
Your date is valid
06/01/1989
$ sh valid.sh
Enter the date to validate
DD
32
MM

03
YYYY
1999
Invalid date

Practical No. :9
Aim: Write a shell script to calculate area of circle, rectangle, square and
triangle.
$ cat > area.sh
#!/bin/bash
echo "Your choice"
choice=1
while test $choice -ne 0
do
echo "Choices are: "
echo "1. Area of Circle"
echo "2. Area of Square"
echo "3. Area of Rectangle"
echo "4. Area of Traingle"
echo "0. Exit"
echo "Enter your choice"
read choice
case $choice in
1) echo "Enter the radius"
read r
echo "The area of circle is "
echo 3.14\*$r\*$r | bc;;
2) echo "Enter the side of square"
read side
echo "The area of square is "
echo $side\*$side | bc;;
3) echo "Enter the length"
read lr
echo "Enter the breadth"
read br
echo "The area of rectangle is "
echo $lr\*$br | bc ;;
4) echo "Enter the base length"
read bs
echo "Enter the height"
read hg
echo "The area of triangle is "
echo 0.5\*$bs\*$hg | bc ;;
0) exit ;;
*) echo "Invalid input";;
esac
done

Output:
$ sh area.sh
Your choice
Choices are:
1. Area of Circle
2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice 1
Enter the radius
1
The area of circle is
3.14
Choices are:
1. Area of Circle
2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice
2
Enter the side of square
4
The area of square is
16
Choices are:
1. Area of Circle
2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice
3
Enter the length
3
Enter the breadth
4
The area of rectangle is
12
Choices are:
1. Area of Circle
2. Area of Square
3. Area of Rectangle

4. Area of Traingle
0. Exit
Enter your choice
0

Practical No. :10


Aim: To generate mark sheet using file handling
$ cat > db1
#!/bin/bash
i=2
while [ $i -le 6 ]
do
case $i in
2) sed -n '2w temp' database ;;
3) sed -n '3w temp' database ;;
4) sed -n '4w temp' database ;;
5) sed -n '5w temp' database ;;
6) sed -n '6w temp' database ;;
esac
m1=`cut -d " " -f3 temp`
m2=`cut -d " " -f4 temp`
m3=`cut -d " " -f5 temp`
total=`expr $m1 + $m2 + $m3`
i=`expr $i + 1`
per=`expr $total / 3`
echo "Total = $total, Percentage = $per"
done
$ cat > database
roll name m1 m2 m3
1 neha 80 90 90
2 seema 80 80 90
3 puja 70 90 80
4 priya 80 90 50
5 prachiti 60 80 70
Output:
$ sh db1
Total = 260, Percentage = 86
Total = 250, Percentage = 83
Total = 240, Percentage = 80
Total = 220, Percentage = 73
Total = 210, Percentage = 70

Practical No. :11


Aim : To write a script which accepts 2 strings, find the length of the string,
concatenate both the strings & print the string in reverse.
$ cat > stringfun.sh
#!/bin/bash
echo "Enter the string 1"
read str1
echo "Enter the string 2"
read str2
choice=1
while [ $choice -ne 0 ]
do
echo "enter 1 => String length"
echo "enter 2 => String concatenation"
echo "enter 3 => Reversing the string"
echo "enter 0 => exit"
read choice
case $choice in
1) echo "The length of the first string is "
n=`expr $str | wc -c`
echo $n
echo "The length of the second string is "
n=`expr $str2 | wc -c`
echo $n
;;
2) echo "The concatenated string is "
echo $str1|$str2;;
3) echo "The reversed string is: "
z=`echo $str1 | wc -m`
while test $z -gt 0
do
echo -n `echo $str1 | cut -c $z`
done
;;
esac
done

Output:
$ sh stringfun.sh
Enter the string 1
Mumbai
Enter the string 2
Indians
enter 1 => String length
enter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
1
The length of the first string is
7
The length of the second string is
8
enter 1 => String length
enter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
2
The concatenated string is
MumbaiIndians
enter 1 => String length
enter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
0

Você também pode gostar