Working With Basic Command
Working With Basic Command
no:1
Date: 05/07/18
Working with Basic Command
*******************************************************************************
*
AIM:
To write a linux script to work with Basic Command
CODING:
clear
echo "working with basic command"
echo "**************************"
echo "calendar"
echo "********"
cal
echo "date"
echo "****"
date
echo "user name"
echo "*********"
who
echo "terminal type"
echo "*************"
tty
OUTPUT:
system1@system1-Veriton-Series:~$ cd chitra
system1@system1-Veriton-Series:~/chitra$ sh 1.sh
working with basic command
**************************
calendar
********
October 2018
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 31
date
****
Mon Oct 1 16:10:15 IST 2018
user name
*********
system1 :0 2018-10-01 16:02 (:0)
system1 pts/0 2018-10-01 16:09 (:0)
terminal type
*************
/dev/pts/0
RESULT:
1
Thus the program was succesfully executed.
Ex.no:2
Date: 05/07/18
Working with LS Command
*******************************************************************************
*
AIM:
To write a linux script to work with LS Command
CODING:
clear
echo "working with ls command"
echo "***********************"
echo "list of file"
echo "************"
ls
echo "list of file with more information"
echo "**********************************"
ls -l
echo "list of file with time orter"
echo "****************************"
ls -t
echo "list of file with used order"
echo "****************************"
ls -u
echo "list of file in reverse order"
echo "*****************************"
ls -r
OUTPUT:
2
8.sh 5.sh 2.sh~ 20.sh~ 18.sh 15.sh 12.sh
RESULT:
AIM:
To write a linux script to Count Number of Files and Directories
CODING:
clear
nf=`ls -l | grep -c "^-"`
nd=`ls -l | grep -c "^d"`
echo "number of files:$nf"
echo "number of directories:$nd"
OUTPUT:
number of files:46
number of directories:0
3
RESULT:
Ex.no:4
Date: 23/07/18
Total Number of Users
*******************************************************************************
*
AIM:
To write a linux script to display Total Number of Users
CODING:
clear
echo "total number of users"
echo "********************"
who | wc -l
OUTPUT:
4
RESULT:
Ex.no:5
Date: 30/08/18
TR Command
*******************************************************************************
*
AIM:
To write a linux script to convert lowercase to uppercase using TR command
CODING:
clear
echo "TR command"
echo "**********"
ls
echo "enter one file name"
read fn
if [ -f $fn ]
then
echo "file is exist"
tr "[a-z]" "[A-Z]" < $fn
else
echo "file is not exist"
fi
OUTPUT:
TR command
**********
10.sh 12.sh~ 15.sh 17.sh~ 1.sh 22.sh 3.sh 5.sh~ 8.sh test
10.sh~ 13.sh 15.sh~ 18.sh 20.sh 22.sh~ 3.sh~ 6.sh 8.sh~
11.sh 13.sh~ 16.sh 18.sh~ 20.sh~ 2.sh 4.sh 6.sh~ 9.sh
11.sh~ 14.sh 16.sh~ 19.sh 21.sh 2.sh~ 4.sh~ 7.sh 9.sh~
12.sh 14.sh~ 17.sh 19.sh~ 21.sh~ 30.sh 5.sh 7.sh~ spirel.docx
enter one file name
test
file is exist
HAI
HOW ARE YOU
I AM FINE
5
RESULT:
Ex.no:6
Date: 24/9/18
Copy & Rename the File
*******************************************************************************
*
AIM:
To write a linux script to Copy & Rename the File.
CODING:
clear
echo "copy & Rename the file"
echo "**********************"
echo "menu"
echo "****"
echo "1. copy"
echo "2.Rename"
read ch
case $ch in
1)echo "copy the file"
echo "*************"
echo "enter old the file name"
read f1
echo "enter the new file name"
read f2
cp $f1 $f2;;
2)echo "Rename the file"
echo "***************"
echo "enter the old file name"
read f1
echo "enter the new file name"
read f2
mv $f1 $f2;;
esac
OUTPUT:
6
2.Rename
1
copy the file
*************
enter old the file name
test
enter the new file name
raji
RESULT:
AIM:
To write a linux script to Compare two files
CODING:
clear
echo "compare using cmp commmand"
echo "enter the file name"
read f1 f2
echo "contents of" $f1
cat $f1
echo "contants of" $f2
cat $f2
echo "compare using cmp commands"
if ( cmp $f1 $f2 )
then
echo "two files are similar"
else
echo "two files are not similar"
fi
OUTPUT:
compare using cmp commmand
enter the file name
sa sa1
contents of sa
Hai
How are you?
contants of sa1
hello
I am fine
compare using cmp commands
sa sa1 differ: byte 1, line 1
two files are not similar
7
RESULT:
Ex.no:8
Date: 16/10/18
Append Two Files
*******************************************************************************
*
AIM:
To write a linux script to Append two files
CODING:
clear
echo "enter the first file name"
read a
echo "enter the second file name"
read b
if test -f $a
then
if test -f $b
then
echo "content of the first file"
cat $a
echo "content of the second file"
cat $b
cat >>$a $b
echo "appending after second file"
cat $a
else
echo "file do not exists"
fi
fi
OUTPUT:
8
Hai
How are you?
content of the second file
hello
I am fine
appending after second file
Hai
How are you?
hello
I am fine
RESULT:
Ex.no:9
Date: 23/07/18 Print N Value In Reverse Order
*******************************************************************************
*
AIM:
To write a linux script to Print N Value In Reverse Order
CODING:
clear
a=5
while [ $a -gt 0 ]
do
echo $a
a=`expr $a - 1`
done
OUTPUT:
5
4
3
2
1
9
RESULT:
Ex.no:10
Date: 23/07/18
Average Calculation
*******************************************************************************
*
AIM:
To write a linux script to Average Calculation
CODING:
clear
echo "enter the five values"
read a b c d e
t=`expr $a + $b + $c + $d + $e `
avg=`expr $t / 5 `
echo $t
echo $avg
OUTPUT:
10
RESULT:
Ex.no:11
Date: 30/07/18
Factorial Calculation
*******************************************************************************
*
AIM:
To write a linux script to Factorial Calculation
CODING:
clear
echo "enter the n value"
echo "*****************"
read n
f=1
while [ $n -gt 0 ]
do
f=`expr $f \* $n`
n=`expr $n - 1`
done
echo $f
OUTPUT:
11
RESULT:
Ex.no:12
Date: 7/08/18
Swapping Two Values
*******************************************************************************
*
AIM:
To write a linux script to swap two values.
CODING:
clear
echo "SWAPPING"
echo "********"
echo "Enter the values:"
read a b
echo "Before swapping\n"
echo "$a \t $b"
t=$a
a=$b
b=$t
echo "After swapping\n"
echo "$a \t $b"
OUTPUT:
SWAPPING
********
Enter the values:
56 67
12
Before swapping
56 67
After swapping
67 56
RESULT:
Ex.no:13
Date: 7/08/18
Biggest Among Three Numbers
*******************************************************************************
*
AIM:
To write a linux script to Count Number of Files and Directories
CODING:
clear
echo "Biggest among three numers"
echo "**************************"
echo "enter the a,b,c values"
read a b c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "a is biggest number"
else
if [ $b -gt $a ] && [ $b -gt $c ]
then
echo "b is biggest number"
else
echo "c is biggest number"
fi
fi
13
OUTPUT:
Biggest among three numers
**************************
enter the a,b,c values
245
c is biggest number
RESULT:
Ex.no:14
Date: 21/08/18
Checking Palindrome Number
*******************************************************************************
*
AIM:
To write a linux script to check given number is palindrome or not
CODING:
clear
echo "palindrome or not"
echo "*****************"
echo "enter one number"
read a
n=$a
s=0
while [ $a -gt 0 ]
do
r=`expr $a % 10`
s=`expr $s \* 10 + $r`
a=`expr $a / 10`
done
if [ $n -eq $s ]
then
echo "the $n is palindrome"
14
else
echo "the $n is not palindrome"
fi
OUTPUT:
palindrome or not
*****************
enter one number
121
the 121 is palindrome
RESULT:
Ex.no:15
Date: 5/09/18 Arithmetic Operation
*******************************************************************************
*
AIM:
To write a linux script to do Arithmetic Operation
CODING:
clear
echo "ARITHMETIC OPERATIONS"
echo "*********************"
echo "menu"
echo "****"
echo "(1)ADDITION"
echo "(2)SUBTRACTION"
echo "(3)MULTIPLICATION"
echo "(4)DIVISION"
echo "enter the two number"
read a b
echo "enter the choice"
read c
case $c in
15
(1) d=`expr $a + $b`;;
(2) d=`expr $a - $b`;;
(3) d=`expr $a \* $b`;;
(4) d=`expr $a / $b`;;
(*)exit;
esac
echo "result" $d
OUTPUT:
ARITHMETIC OPERATIONS
*********************
menu
****
(1)ADDITION
(2)SUBTRACTION
(3)MULTIPLICATION
(4)DIVISION
enter the two number
23 45
enter the choice
3
result 1035
RESULT:
Ex.no:16
Date: 5/09/18
Multiplication Table
*******************************************************************************
*
AIM:
To write a linux script to display multiplication table
CODING:
clear
echo "Enter the Table value"
read n
echo "Enter the ending value"
read e
i=1
while [ $e -ge $i ]
do
r=`expr $i \* $n`
echo "$i * $n =$r"
i=`expr $i + 1`
done
16
OUTPUT:
enter the Table value
7
enter the ending value
9
1 * 7 =7
2 * 7 =14
3 * 7 =21
4 * 7 =28
5 * 7 =35
6 * 7 =42
7 * 7 =49
8 * 7 =56
9 * 7 =63
RESULT:
Ex.no:17
Date: 24/09/18
Student Mark Details
*******************************************************************************
*
AIM:
To write a linux script to display student mark details
CODING:
clear
echo "student name"
read n
echo "roll no"
read r
echo "Tamil"
read t
echo "English"
read e
echo "Maths"
read m
17
echo "NAME:$n"
echo "ROLL NO:$r"
echo "Tamil:$t"
echo "ENGLISH:$e"
echo "MATHS:$m"
tot=`expr $t + "$e + $m `
echo "THE RESULT IS:$tot"
avg=`expr $tot / 3 `
echo "AVERAGE IS:$avg
OUTPUT:
student name
Raji
roll no
1201
Tamil
90
English
90
Maths
90
NAME:Raji
ROLL NO:1201
Tamil:90
ENGLISH:90
MATHS:90
THE RESULT IS:270
AVERAGE IS:90
RESULT:
Ex.no:18
Date: 24/09/18
Convert Decimal to Hexa
*******************************************************************************
*
AIM:
To write a linux script to Convert Decimal to Hexa
CODING:
clear
echo "Decimal to hexa number"
echo "**********************"
echo "enter the Decimal number"
read n
t=$n
s=0
f=1
while [ $n -gt 0 ]
18
do
r=`expr $n % 16`
n=`expr $n / 16`
s=`expr $s + $r \* $f`
f=`expr $f \* 10`
done
echo "decimal-->" $t "hexa---->" $s
OUTPUT:
RESULT:
Ex.no:19
Date: 1/10/18
Draw Pattern
*******************************************************************************
*
AIM:
To write a linux script to Draw Pattern
CODING:
clear
echo "Draw pattern"
echo "************"
echo "enter the n value"
read n
i=1
j=1
while [ $i -le $n ]
19
do
j=1
while [ $j -le $i ]
do
echo -n $i
j=`expr $j + 1`
done
echo " "
i=`expr $i + 1`
done
OUTPUT:
Draw pattern
************
enter the n value
5
1
22
333
4444
55555
RESULT:
Ex.no:20
Date: 1/10/18
Sum Of Digit & Reverse Number
*******************************************************************************
*
AIM:
To write a linux script to dispaly sum of digit
CODING:
clear
echo "sum of digit and reverse number"
echo "******************************"
echo "enter the value"
echo "*****************"
read n
20
s=0
rev=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s + $r`
rev=`expr $rev \* 10 + $r`
n=`expr $n / 10`
done
echo "sum of digit" $s
echo "reverse number" $rev
OUTPUT:
RESULT:
Ex.no:21
Date: 1/10/18
Add Two Real Numbers
*******************************************************************************
*
AIM:
To write a linux script to add two real numbers
CODING:
clear
echo "Add to real number"
echo "******************"
21
echo "enter the two values"
read a b
if [ $a -gt 0 -a $b -gt 0 ]
then
c=`expr $a + $b`
else
echo "please enter two real number"
fi
echo "result" $c
OUTPUT:
RESULT:
Ex.no:22
Date: 1/10/18
Calculate Electricity Bill
*******************************************************************************
*
AIM:
To write a linux script to Calculate Eb Bill
CODING:
clear
22
echo "enter the customer name"
read na
echo "enter current reading"
read cur
echo "enter previous reading"
read pre
co=`expr $cur - $pre`
if [ $co -le 100 ]
then
amt=`expr $co \* 1`
else
amt=`expr $co \* 2`
fi
echo "customer name is $na"
echo "bill amonut is $amt"
OUTPUT:
RESULT:
23