Semester IV Linux Lab Record
Semester IV Linux Lab Record
Content of file 2
This is file 2 content
This is second line of the file
Output
1.Current user and his login name
2.Current shell, Home directory, Operating system, Current path, Current
working directory
3.Current login number of all users, show all available shells
4.CPU information like process type , speed
5.Memory information like program type
Current shell
------------
/bin/bash
Home directory
--------------
/home/iiit
Output
1.Pipes
2.Redirection
3.tee command
Enter your choice
1
Pipes Operation - Combing ls and sort command
-----------------------------------------------
file1 file2 file3 movefile numbers prg10.sh
prg1.sh prg2.sh prg3.sh prg4.sh prg5.sh prg6.sh
prg7.sh prg8.sh prg9.sh xsfileaa xsfileab
Output
Removing Zero Byte Files
List of file before removing the zero bytes
###########################################
data1 data2 data3 numbers prg10.sh prg1.sh
prg2.sh prg3.sh prg4.sh prg5.sh prg6.sh prg7.sh
prg8.sh prg9.sh rmfile1 rmfile2 sort-number xsfileaa
xsfileab
file rmfile1 is removed
file rmfile2 is removed
List of the files after removing the zero byte files
####################################################
data1 data2 data3 numbers prg10.sh prg1.sh
prg2.sh prg3.sh prg4.sh prg5.sh prg6.sh prg7.sh
prg8.sh prg9.sh sort-number xsfileaa xsfileab
7. Sum of Individual Digits
Aim:
Write a shell script to find the sum of the individual digits of a given number.
Algorithm:
1. Start the Process
2. Open a new shell script using vi editor
3. Read a number which has more than one digit
4. Find the sum of the digit
5. Display the sum of the digit
6. Terminate the process.
Coding:
clear
echo "Enter The Number"
read n
while test $n -ne 0
do
n1 = `expr $n % 10`
sum = `expr $sum + $n1`
n=`expr $n / 10`
done
echo "The Sum is ${sum}"
Output
Enter The Number
5978
The Sum is 29
8. Finding the Greatest Number
Aim:
Write a shell script to find the greatest among the given set of numbers using command line
arguments.
Algorithm:
1. Start the Process
2. Open a new shell script using vi editor
3. Read the numbers from command line
4. Find the greatest number by comparing the numbers with each other.
5. Display the greatest number
6. Terminate the process.
Coding:
clear
echo "Greatest number"
echo “###############”
n=$#-1
big=$1
for ((i=1;i<=n;i=i+1))
do
if [ $big -lt $2 ]
then
big=$2
fi
shift
done
echo "The greatest number is $big"
Output
chmod u+x prg8.sh
./prg8.sh 5 2 1 9 7
Greatest number
###############
The greatest number is 9
9. Palindrome checking.
Aim:
Write a shell script for palindrome checking.
Algorithm:
1. Start the Process
2. Open a new shell script using vi editor
3. Read a string from the user
4. Check whether given string is palindrome or not
5. Display the result
6. Terminate the process.
Coding:
clear
echo "Enter the String"
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
l=`expr $len / 2`
ctr=1
flag=0
while [ $ctr -le $l ]
do
a=`echo $str | cut -c$ctr`
b=`echo $str | cut -c$len`
if [ $a != $b ]
then
flag=1
break
fi
ctr=`expr $ctr + 1`
len=`expr $len - 1`
done
if test $flag -eq 0
then
echo "The given String is Palindrome"
else
echo "The given String is not a Palindrome"
fi
Output
Enter the String
malayalam
Algorithm:
1. Start the Process
2. Open a new shell script using vi editor
3. Read the number for which multiplication table to be generated
4. Display the multiplication table.
5. Terminate the process.
Coding:
clear
echo "Multiplication table"
echo “********************”
echo "Enter the number for which table to be generated: "
read m
echo "Enter the range"
read r
for (( n=1; n<=r; n++ ))
do
c=$(($n*$m))
echo " $n * $m=$c"
done
Output
Multiplication table
********************
Enter the number for which table to be generated:
9
Enter the range
10
1 * 9=9
2 * 9=18
3 * 9=27
4 * 9=36
5 * 9=45
6 * 9=54
7 * 9=63
8 * 9=72
9 * 9=81
10 * 9=90