0% found this document useful (0 votes)
28 views8 pages

Os Practical File

Uploaded by

kinhishere1234
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)
28 views8 pages

Os Practical File

Uploaded by

kinhishere1234
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/ 8

SMT G.G.

KHADSE COLLEGE MUKTAINAGAR


Semester-III
BCA-305 Lab on Operating System
INDEX

Ex. Page
NO. Title No.
Date Remark

Demonstration of Linux commands with


attributes: - pwd, cd, ls, more, less, echo, clear,
1
kill, ps, man, cal, date, who, who am I, wc, mkdir,
rmdir, rm, sort.

Write a shell script to display first 20 terms of


2 Fibonacci series.

Write a shell script to display current time of


3 system and display the message according to
the time.

Write a shell script to check the user is login or


4
not and say hello.

Write a shell script to calculate factorial of a


5 number.

Write a shell script to check number is divisible


6 by 7 or not.

Write a shell script to check number is prime or


7
not.
Write a shell script to check number is
8 palindrome or not.

Write a shell script to check number is


9 Armstrong or not.

Write a shell script to create result sheet using


10 redirection and filters. (Using Head, tail,
cut, paste)

Batch In-Charge Head of Department

0
Practical No.1
Demonstration of Linux commands with attributes: - pwd, cd, ls, more, less, echo, clear, kill, ps,
man, cal, date, who, who am I, wc, mkdir, rmdir, rm, sort.

1.pwd command : Print Working Directory.


rohit@rohit-virtualBox:~$ cd rohit
rohit@rohit-virtualBox:~/rohit$ pwd
/home/rohit/vishnu

2.cd command : Change Directory – use to change current working directory to another
directory.
rohit@rohit-virtualBox:~$ cd rohit
rohit@rohit-virtualBox:~/rohit$

3.ls command : List – list files and directories within a system .


rohit@rohit-virtualBox:~/rohit$ ls
divisible_by7.sh palindrome.sh factorial.sh prime_number.sh

4.more command : Use to view the text file in command prompt .


rohit@rohit-virtualBox:~/rohit$ more hello.txt
hello

5.less command : Viewing file content interactively.


rohit@rohit-virtualBox:~/rohit$ less -1 hello.txt
hello
hello.txt(END)

6.echo command : Use to print massage on terminal.


rohit@rohit-virtualBox:~/rohit$ echo “hello”
hello

7.clear command : Use to clear the terminal.


rohit@rohit-virtualBox:~/rohit$ clear
rohit@rohit-virtualBox:~/rohit$

8.ps command : Process - To list all processes in your current shell.


PID TTY TIME CMD
23564 pts/5 00:00:00 bash
24346 pts/5 00:00:00 ps

9.who command : displays information about users who are currently logged in to the system.
rohit@rohit-virtualBox:~/rohit$ who
rohit seat0 2024-09-02 19:38 (login screen)
rohit tty2 2024-09-02 19:38

10.wc command : It used to know the number of line, characters, words in file.
rohit@rohit-virtualBox:~/rohit$ wc hello.txt
2 2 12 hello.txt

11.mkdir command : Make Directory – Use to make a directory on current location.


rohit@rohit-virtualBox:~/rohit$ mldir prashant
rohit@rohit-virtualBox:~/rohit$

1
12.rmdir command : Remove directory – Use to remove an a empty directory.
rohit@rohit-virtualBox:~/rohit$ rmdir prashant
rohit@rohit-virtualBox:~/rohit$

13.rm command : Remove – Use to remove a empty file.


rohit@rohit-virtualBox:~/rohit$ rm prashant .sh
rohit@rohit-virtualBox:~/rohit$

14.sort command : It is use to sort the file content.


rohit@rohit-virtualBox:~/rohit$ sort
rohit@rohit-virtualBox:~/rohit$

16.kill command : It is use to kill process


rohit@rohit-VirtualBox:~/rohit$ ps
PID TTY TIME CMD
67250 pts/0 00:00:00 bash
67266 pts/0 00:00:00 ps
rohit@rohit-VirtualBox:~/rohit$ kill 67250
rohit@rohit-VirtualBox:~/rohit$

17.whoami command : It is use to show the current user login into your system.
rohit@rohit-VirtualBox:~/rohit$ whoami
rohit

18.date command : To see the current system date and time.


rohit@rohit-VirtualBox:~/rohit$ date
Thu Sep 19 12:59:14 PM IST 2024

19.cal command : To see the calendar for the current month.


rohit@rohit-VirtualBox:~$ cal
September 2024
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

20.man command : Manual which gives information about most commands.


rohit@rohit-VirtualBox:~/rohit$ man whoami
WHOAMI(1)

NAME
whoami - print effective user name

SYNOPSIS
whoami [OPTION]...

DESCRIPTION
Print the user name associated with the current effective user ID. Same as id -un.

--help display this help and exit

--version
output version information and exit

AUTHOR
Written by Richard Mlynarik.

2
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or
later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to
the extent permitted by law.

SEE ALSO
Full documentation <https://www.gnu.org/software/coreutils/whoami>
or available locally via: info '(coreutils) whoami invocation'

GNU coreutils 9.4 April 2024

WHOAMI(1)
~
~
~
~
Manual page whoami(1) line 1/32 (END) (press h for help or q to quit)

Practical No. 2
Write a shell script to display first 20 terms of Fibonacci series.

#!/bin/bash
a=0
b=1
echo "term:"
for((i=0;i<20;i++))
do
fib=$((a+b))
a=$b
b=$fib
echo "$fib"
done

Output :--
1,2,3,5,8,13,21,34,55,89,144,233,377,610,967,1597,2584,4181,6765,10946

Practical No. 3
Write a shell script to display current time of system and display the message according to the
time.
#!/bin/bash
echo " time :-$(date +%H:%M:%S:%N)"
echo "hours :- $(date +%H)"
echo "minutes :- $(date +%M)"
echo "seconds :- $(date +%S)"
echo "n seconds :- $(date +%N)"

Output :--

time :- 02:12:07:358971055
hour :- 02
minutes :- 12
seconds :-07
n seconds :- 369872607

3
practical No. 4
Write a shell script to check the user is login or not and say hello.

#!/bin/bash
echo "enter user name :"
read name
who > test
if grep $name test
then
echo " you’re logged in"
echo "hello!"
else
echo "not logged in"
fi

Output :--

enter user name :


rohit
rohit seat0 2024-09-02 19:33 (login screen)
rohit tty2 2024-09-02 19:33 (tty2)
you're logged in
hello!

Practical No. 5
Write a shell script to calculate factorial of a number.

#!/bin/bash
echo "enter the number for factorial : "
read num
fact=1
for((i=1;i<=num;i++))
do
fact=$((fact*i))
done
echo "factorial of $num is :$fact"

Output :--

enter the number for factorial :


5
factorial of 5 is :120

Practical No. 6
Write a shell script to check number is divisible by 7 or not.

#!/bin/bash
echo "enter number :"
read num
if((num%7==0))
then
echo "divisible"
else
echo "not divisible"
fi

Output :--

enter number :
21
divisible

4
Practical No.7
Write a shell script to check number is prime or not.

#!/bin/bash
echo "enter the number : "
read num
for((i=2;i*i<=num;i++))
do
if((num%i==0))
then
echo "not prime"
break
fi
echo "number is prime"
done
if((num<=1))
then
echo "not prime"
break
fi

Output :--

enter the number :


5
number is prime

practical no. 8
Write a shell script to check number is palindrome or not.

#!/bin/bash
echo "enter number : "
read num
reverse=0
for((temp=num;temp>0;temp/=10))
do
reverse=$((reverse*10+temp%10))
done
if((num==reverse))
then
echo "palindrome"
else
echo "not palindrome"
fi

Output :--

enter number :
1221
palindrom

5
Practical No.9
Write a shell script to check number is Armstrong or not.

#!/bin/bash
echo "enter number :"
read num
sum=0
original=$num
while((num!=0))
do
digit=$((num%10))
sum=$((sum+digit*digit*digit))
num=$((num/10))
done
if((original==sum))
then
echo "armstrong"
else
echo "not armstrong"
fi

Output :--

enter number :
153
Armstrong

Practical No. 10
Write a shell script to create result sheet using redirection and filters. (Using Head, tail, cut,
paste).

#!/bin/bash
echo "name,mathscore,historyscore">result.csv
echo "prashant,67,56">>result.csv
echo "vishnu,87,46">>result.csv
echo "rohit,88,75">>result.csv

Output :-- (operations performrd in terminal)

rohit@rohit-VirtualBox:~/rohit$ cat result1.csv


name,mathscore,historyscore
prashant umbarkar,67,56
vishnu dhivar,87,46
rohit lonagare,88,75
rohit@rohit-VirtualBox:~/rohit$ sort result1.csv
name,mathscore,historyscore
prashant umbarkar,67,56
rohit lonagare,88,75
vishnu dhivar,87,46
rohit@rohit-VirtualBox:~/rohit$ head -2 result1.csv
name,mathscore,historyscore
prashant umbarkar,67,56
rohit@rohit-VirtualBox:~/rohit$ tail +3 result1.csv
vishnu dhivar,87,46
rohit lonagare,88,75
rohit@rohit-VirtualBox:~/rohit$ cut -d, -f1,2 result1.csv
name,mathscore
prashant umbarkar,67
vishnu dhivar,87
rohit lonagare,88
rohit@rohit-VirtualBox:~/rohit$ cut -d, -f1,3 result2.csv | paste - result1.csv
name,mathscore,historyscore

6
prashant umbarkar,67,56
vishnu dhivar,87,46
rohit lonagare,88,75
roshan mahale,57,67

You might also like