Professional Documents
Culture Documents
Practical File
Integrated Institute of
Technology
Dwarka Sec – 9, New Delhi – 110077
Aim 1 :
Introduction To Linux Based System
In the above image, the user process executes in the user mode until it
gets a system call. Then a system trap is generated and the mode bit is
set to zero. The system call gets executed in kernel mode. After the
execution is completed, again a system trap is generated and the mode
bit is set to 1. The system control returns to kernel mode and the process
execution continues.
Necessity of Dual Mode (User Mode and Kernel Mode) in Operating
System The lack of a dual mode i.e user mode and kernel mode in an
operating system can cause serious problems. Some of these are −
Basic Features
Architecture
$who
Aim 3:
Write a linux command to display your system details
$lscpu
Aim 4:
Write the linux command to perform calculations
$bc
Aim 5:
Write the linux command to show the current working directory
$pwd
Aim 6:
Write the linux command to get help with various options
$help
$man {command-
name} eg. $man ls
Aim 7:
Write the linux command to display what all users are currently
doing
$w
Aim 8:
Write the linux Command to copy a file to some other Iocation
$mv {filename}
{directoryname} eg. $mv
redYellow.txt darkcolor
Aim 10:
Write the linux command to compare the contents of two files
$cmp {firstfilename}
{secondfilename} eg. $cmp s1 s2
Aim 11:
Write the linux command to show the difference between the
contents of two files
$diff {filename1}
{filename2} eg. $diff s1 s2
Aim 12:
Write the linux command to show the common data of two file
$alias
Aim 14:
Write the linux command to display the hostname of the
system and OS
$hostname
Aim 15:
Write the linux command to search for specific pattern in a file
$grep “pattern”
{filename} eg. $grep
“am” s1
Aim 16:
Write the linux command to show the use of basic regular
expressions using grep Command
#!/bin/bash
echo "a shell script to find out the large between two number."
echo -n "First number:"
read fst_num
echo -n "Second number:"
read snd_num
if test $fst_num -gt $snd_num
then
echo $fst_num is greater than $snd_num.
else
echo $snd_num is greater than $fst_num.
fi
Output :
Aim 21:
Write a shell script to check whether a number is even or odd
#!/bin/bash
echo " Enter a number to check whether it is a even or odd : "
read num
if [[ $((num%2)) == 0 ]]
then
echo " $num is an even number "
else
echo " $num is a odd number "
fi
Output :
Aim 22:
Write a shell script to find largest of three given number
#!/bin/bash
echo "Greatest of three : "
echo "Enter three numbers : "
read num1
read num2
read num3
if [[ $num1 -eq $num2 || $num1 -gt $num2 ]]
then
if [ $num1 -lt $num3 ]
then
max=$num3
else
max=$num1
fi
elif [ $num2 -gt $num1 ]
then
if [ $num2 -lt $num3 ]
then
max=$num3
else
max=$num2
fi
fi
echo " max : $max"
echo $'\n'
Output :
Aim 23:
Write a shell script to greet the user according to the day of the
week
#!/bin/bash
day=$(date '+%Y-%m-%d')
echo "Have a nice $day, sir"
Output :
Aim 24:
Write a shell script to display the number of vowels and
consonants in a string
#!/bin/bash
echo "Enter a string : "
read string
vowelCount=$(echo $string | grep -o -i "[aeiou]" | wc --lines)
consonantCount=$(echo $string | grep -o -i "[bcdfghjklmnpqrstvwxyz]" | wc --
lines)
echo "Total number of vowel are : $vowelCount"
echo "Total number of consonants are : $consonantCount"
Output :
Aim 25:
Write a shell script to perform arithmetic operation using case-
--esac
# !/bin/bash
Output :
Aim 26:
Write a shell script to count words, lines and characters in a
file
#!/bin/bash
echo "Enter the file name to count words, line and character: "
read file
lines=$(wc --l < $file)
words=$(wc --w < $file)
chars=$(wc --c < $file)
echo "lines = $lines"
echo "words = $words"
echo "chars = $chars"
Output :
Aim 27:
Write a shell script to check whether the year entered is leap
or not
#!/bin/bash
echo "Enter the year : "
read year
if [ $((year%4)) -eq 0 ]
then
echo "$year is a leap year."
else
echo "$year is not a leap year."
fi
Output :
Aim 28:
Write a shell script to find factorial of a number
#!/bin/bash
echo "Enter a Number : "
read num
factorial=1
while (($num >= 1))
do
factorial=$((factorial*num))
num=$((num-1))
done
echo " factorial of the number is : $factorial"
Output :
Aim 29:
Write a shell script to generate a multiplication table
#!/bin/bash
echo "Table of any number"
read -p "Enter a number : " num
echo
for i in {1..10..1}
do
table=$((num*i))
echo " $num x $i = $table "
done
Output :
Aim 30:
Write a shell script to add the digits of a number
#!/bin/bash
read -p"Enter a number : " number
sum=0
dup=number
while [[ $dup != 0 ]]
do
rem=$((dup%10))
sum=$((sum+rem))
dup=$((dup/10))
done
if [ $number -gt 0 ]
then
echo "Sum of all the digits of $number : $sum "
else
echo "Sum of all the digits of $number : $((-sum))"
fi
Output :
Aim 31 :
Write a shell script to reverse string
#!/bin/bash
read -p"Eneter the String : " string
echo "Reverse of the string : "
RED='\033[0;31m'
echo -e "${RED} $(rev <<< $string)"
Output :
Aim 32 :
Write a shell script to check whether a number entered is
prime or not
#!/bin/bash
echo " Enter a number to check whether it is prime or composite "
read num
counter=0
i=2
div=$((num/2))
while [ $i -le $div ]
do
if [ $((num%i)) == 0 ]
then
counter=1
break
fi
i=$((i+1))
done
if [ $counter == 0 ]
then
echo " $num is a prime number "
else
echo " $num is a composite number "
fi
Output :
Aim 33 :
Write a shell script to accept a filename as command line
argument and print its contents
#!/bin/bash
echo "Enter file name : "
read file
cat < $file
Output :
The End