Os Practical File
Os Practical File
Ex. Page
NO. Title No.
Date Remark
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.
2.cd command : Change Directory – use to change current working directory to another
directory.
rohit@rohit-virtualBox:~$ cd rohit
rohit@rohit-virtualBox:~/rohit$
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
1
12.rmdir command : Remove directory – Use to remove an a empty directory.
rohit@rohit-virtualBox:~/rohit$ rmdir prashant
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
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.
--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'
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 :--
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 :--
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 :--
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
6
prashant umbarkar,67,56
vishnu dhivar,87,46
rohit lonagare,88,75
roshan mahale,57,67