Professional Documents
Culture Documents
1 - Merged 1 17 - Merged 1
1 - Merged 1 17 - Merged 1
Practical: 01
Aim : Study of Unix/
Linux
Unix is an Operating System that is truly the base of all Operating Systems
like Ubuntu, Solaris, POSIX, etc. It was developed in the 1970s by Ken
Thompson, Dennis Ritchie, and others in the AT&T Laboratories. It was
originally meant for programmers developing software rather than non-
programmers.
Security: UNIX has a robust security model that includes file permissions,
user accounts, and network security features.
Linux is a powerful and flexible family of operating systems that are free to
use and share. It was created by a person named Linus Torvalds in 1991.
Linux is completely free of cost, and expenses are never a hindrance to using
it as an operating system.
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Extremely Flexible
Linux has incorporated itself into embedded products like watches, digital
equipment and supercomputing servers.
Lightweight Infrastructure
Linux consumes lesser storage space, and its installation requires around
4GB to 8GB of disk space.
Even though Linux works on using the command line interface but it can be
converted to be used like windows having a Graphical user interface. This is
done mostly by installing packages. The most common way of having a GUI
on the Linux environment is to log in to Ubuntu server and install its desktop
environment.
End-to-end encryption
Linux allows end-to-end encryption while accessing data thus storing public
keys in the server. All data is password protected and provides
authentication to users. It also allows many security features and provides
file permissions, a secure shell, etc.
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Linux Unix
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 02
Aim: Study of Basic commands to understand the system and
working of Linux/Unix.
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
9. mv: Move or rename files or directories.
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Example: df -h (human-readable
format).
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 03
Aim:1. Write a script to find the smallest of three numbers as
well as largest among three numbers.
echo "Enter three
numbers:" read num1 num2
num3
if [ $num1 -lt $num2 ] && [ $num1 -lt $num3 ]; then
smallest=$num1
elif [ $num2 -lt $num1 ] && [ $num2 -lt $num3 ]; then
smallest=$num2
else
smallest=$num3
fi
if [ $num1 -gt $num2 ] && [ $num1 -gt $num3 ]; then
largest=$num1
elif [ $num2 -gt $num1 ] && [ $num2 -gt $num3 ]; then
largest=$num2
else
largest=$num3
fi
echo "Smallest number:
$smallest" echo "Largest number:
$largest"
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 04
Aim:1 Write a shell script to generate marksheet of a student.Take
5 subjects, calculate and display total marks, percentage and
Class obtained by the student.
total_subjects=6
total_marks=600
declare -a subject_marks
for ((i = 1; i <= $total_subjects; i++)); do
read -p "Enter marks for Subject $i: "
subject_marks[$i] done
total_obtained=0
for ((i = 1; i <= $total_subjects; i++)); do
total_obtained=$((total_obtained + subject_marks[$i]))
done
percentage=$((total_obtained * 100 /
total_marks)) if ((percentage >= 90)); then
grade="A"
elif ((percentage >= 80)); then
grade="B"
elif ((percentage >= 70)); then
grade="C"
elif ((percentage >= 60)); then
grade="D"
else
grade="F"
fi
echo "Total Marks Obtained: $total_obtained out of $total_marks"
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 05
Aim:1. 1. Write a shell script to find factorial of given
number n
read -p "Enter the number : "
number fact=1
while [ $number -gt 1
] do
fact=$((fact * number))
number=$((number - 1))
done
echo "Result:" $fact
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Figure: 02
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 06
Aim:1. Write a shell script to check whether number is
prime or not.
echo "Enter a number: "
read num
if [ $num -le 1 ]; then
echo "$num is not a prime
number" elif [ $num -gt 1 ]; then
for ((i = 2; i < num; i++)); do
if [ $((num % i)) -eq 0 ]; then
echo "$num is not a prime number"
echo "$i times $((num / i)) is $num"
break
fi
done
if [ $i -eq $num ]; then
echo "$num is a prime number"
fi
fi
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 07
Aim:1. Write a shell script to check whether number is
palindrome or not.
echo -n "Enter a number:
" read num
original=$num
reversed=0
while [ $num -gt 0 ]; do digit=$
((num % 10)) reversed=$
((reversed * 10 + digit)) num=$
((num / 10))
done
if [ $original -eq $reversed ]; then
echo "Number is a
palindrome"
else
echo "Number is NOT a palindrome"
fi
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical:
Aim:1. Write a shell script to check whether number is even or odd.
echo -n "Enter a number:
" read num
rem=$((num % 2))
if [ $rem == 0 ];
then
echo "$num is an even
number" else
echo "$num is an odd number"
fi
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical:
Aim:1. Write a shell script to print Fibonacci series up to
nth element.
read -p "Enter the value of n (number of elements): " n
a=0
b=1
for ((i = 0; i < n; i++));
do echo -n "$a "
next=$((a + b))
a=$b
b=$next
done
echo
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
Practical: 10
Aim:1. Write a shell script to choose one option from the
given menu and to display it.
echo "Menu
Options:" echo "1.
Option A" echo "2.
Option B" echo "3.
Option C" echo "4.
Exit"
read -p "Enter your choice (1/2/3/4): " choice
case $choice in
1)
echo "You selected Option
A" 2)
echo "You selected Option
B" 3)
echo "You selected Option
C" 4)
echo "Exiting the menu"
*)
echo "Invalid choice. Please select a valid option (1/2/3/4)."
esac
OS(21CS2404)/4th Page
Computer Science and
Engineering KSET KPGU
Enrollment number: 2201201073
OUTPUT:
Figure: 01
OS(21CS2404)/4th Page