Linux Lab-1
Linux Lab-1
elif [ "$ch" = 2 ]
then
echo "DISPLAY"
ls
echo "Enter the File Name to be Display"
read a
cat $a
sh f1.sh
1
elif [ "$ch" = 3 ]
then
echo "COPY COMMAND"
ls
echo "Enter File Name for Already Created :"
read f1
echo "Enter File Name for Copied File : "
read f2
cp $f1 $f2
echo "File is Copied"
cat $f2
sh f1.sh
elif [ "$ch" = 4 ]
then
echo "REMOVE COMMAND"
ls
echo "Enter the File Name for Remove :"
read file1
rm $file1
echo "The File is Removed"
ls
sh f1.sh
elif [ "$ch" = 5 ]
then
echo "MOVE COMMAND"
ls
echo " Enter the File Name to be Moved"
read m
echo " Enter the Moved File Path "
read p
mv $m $p
2
echo " File is Moved"
ls
sh f1.sh
elif [ "$ch" = 6 ]
then
ls
echo "COMPARE COMMAND"
echo "Enter the Already Exist First File Name"
read file1
echo "Enter the Already Exist Second File Name"
read file2
echo "First File Content"
cat $file1
echo "Second File Content"
cat $file2
cmp $file1 $file2
sh f1.sh
elif [ "$ch" = 7 ]
then
echo "WORD COUNT COMMAND"
echo "Enter the Already Exist File Name"
read file1
echo "The Content Of the $file1 is"
cat $file1
echo "The Word Count of $file1 is :"
wc $file1
sh f1.sh
3
elif [ "$ch" = 8]
then
echo "SPLIT COMMAND"
ls
echo "Enter File Name to be Split"
read file1
split -d $file1
ls
sh f1.sh
elif [ "$ch" = 9 ]
then
echo "DIFFERENCE COMMAND"
ls
echo "ENTER THE First File"
read file1
echo "Enter the Second File"
read file2
echo "First File Content"
cat $file1
echo "Second File Content"
cat $file2
diff $file1 $file2
sh f1.sh
elif [ "$ch" = 10 ]
then
echo "exit"
fi
4
OUTPUT
5
Enter File Name for Copied File :
sample2
File is Copied
hai, my first linux program
Enter Your Choice : 4
REMOVE COMMAND
Desktop Downloads Music Pictures sample1 Templates
Documents file.sh new1 Public sample2 Videos
Enter the File Name for Remove :
new1
The File is Removed
Desktop Downloads Music Public sample2 Videos
Documents file.sh Pictures sample1 Templates
Enter Your Choice : 5
MOVE COMMAND
Desktop Downloads Music Public sample2 Videos
Documents file.sh Pictures sample1 Templates
Enter the File Name to be Moved
sample1
Enter the Moved File Path
sample2
File is Moved
Desktop Downloads Music Public Templates
Documents file.sh Pictures sample2 Videos
nter Your Choice : 6
Desktop Downloads Music Public sample2 Videos
Documents file.sh Pictures sample1 Templates
COMPARE COMMAND
Enter the Already Exist First File Name
sample1
Enter the Already Exist Second File Name
sample2
First File Content
6
welcome to linux program
Second File Content
hai, my first linux program
sample1 sample2 differ: byte 1, line 1
Enter Your Choice : 7
WORD COUNT COMMAND
Enter the Already Exist File Name
sample1
The Content Of the sample1 is
welcome to linux program
The Word Count of sample1 is :
1 4 25 sample1
7
> hai, my first linux program
Enter Your Choice : 10
mythili@mythili:~$
RESULT:
8
SYSTEM CONFIGURATION DETAILS
clear
echo "SYSTEM CONFIGURATION DETAILS"
echo "----------------------------------------------------- "
echo "a. Currently Loged User : $USER"
echo " Log Name : $LOGNAME"
echo "b. Current Shell : $SHELL"
echo " Home Directory : $HOME"
echo " Operating System Type : $OSTYPE"
echo " Current Path Setting : $PATH"
echo " Current Working Directory : $PWD"
echo "c. Current Logged No.Of.Users :"
who | wc -l
echo " Available Shells:"
cat /etc/shells
echo "d. CPU Information:"
grep "model name" /proc/cpuinfo
echo "e. Memory Information:"
vmstat
9
OUTPUT
mythili@mythili:~$ nano system.sh
mythili@mythili:~$ chmod +x system.sh
mythili@mythili:~$ ./system.sh
SYSTEM CONFIGURATION DETAILS
-----------------------------------------------------
a. Currently Loged User : mythili
Log Name : mythili
b. Current Shell : /bin/bash
Home Directory : /home/mythili
Operating System Type : linux-gnu
Current Path Setting :
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/
snap/bin
Current Working Directory : /home/mythili
c. Current Logged No.Of.Users :
1
Available Shells:
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
d. CPU Information:
model name : AMD PRO A4-4350B R4, 5 COMPUTE CORES 2C+3G
model name : AMD PRO A4-4350B R4, 5 COMPUTE CORES 2C+3G
e. Memory Information:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
10
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 321588 46652 817924 0 0 64 10 101 153 2 1 96 1 0
RESULT
11
PIPES, REDIRECTION AND TEE COMMANDS
echo "1.PIPES"
echo "2.STANDARD INPUT REDIRECTION"
echo "3.STANDARD OUTPUT REDIRECTION"
echo "4.TEE COMMAND"
echo "5.QUIT"
echo -n "ENTER YOUR CHOICE : "
read ch
if [ "$ch" = 1 ]
then
ls -l | grep "^-"
sh pro3.sh
elif [ "$ch" = 2 ]
then
ls
echo "Enter the File Name"
read file1
cat<$file1
sh pro3.sh
elif [ "$ch" = 3 ]
then
ls
echo "Enter the File Name1"
read file1
echo "Enter the File Name2"
read file2
cat $file1 >> $file2
echo "Content of File1"
cat $file1
echo "Content of File2"
cat $file2
12
sh pro3.sh
elif [ "$ch" = 4 ]
then
ls
echo "Enter the File Name"
read file1
cat temp | tree $file1
echo "Content of Temp"
cat temp
sh pro3.sh
elif [ "$ch" = 5 ]
then
echo "Exit"
fi
13
OUTPUT
ythili@mythili:~$ nano pipe.sh
mythili@mythili:~$ chmod +x pipe.sh
mythili@mythili:~$ ./pipe.sh
1.PIPES
2.STANDARD INPUT REDIRECTION
3.STANDARD OUTPUT REDIRECTION
4.TEE COMMAND
5.QUIT
ENTER YOUR CHOICE : 1
-rwxrwxr-x 1 mythili mythili 1896 Mar 26 04:49 file.sh
-rwxrwxr-x 1 mythili mythili 848 Mar 26 05:15 pipe.sh
-rw-rw-r-- 1 mythili mythili 25 Mar 26 04:40 sample1
-rw-rw-r-- 1 mythili mythili 28 Mar 26 04:31 sample2
-rwxrwxr-x 1 mythili mythili 626 Mar 26 05:10 system.sh
-rw-rw-r-- 1 mythili mythili 25 Mar 26 04:52 xaa
ENTER YOUR CHOICE : 2
Desktop Downloads Music pipe.sh sample1 system.sh Videos
Documents file.sh Pictures Public sample2 Templates xaa
Enter the File Name
sample1
welcome to linux program
ENTER YOUR CHOICE : 3
Desktop Downloads Music pipe.sh sample1 system.sh Videos
Documents file.sh Pictures Public sample2 Templates xaa
Enter the File Name1
sample2
Enter the File Name2
sample1
Content of File1
hai, my first linux program
Content of File2
14
welcome to linux program
hai, my first linux program
ENTER YOUR CHOICE : 4
Desktop Downloads Music pipe.sh sample1 system.sh Videos
Documents file.sh Pictures Public sample2 Templates xaa
Enter the File Name
Music
cat: tempMusic
├── f1
│ └── f3
│ └── f4
│ └── f5
└── f2
5 directories, 0 files
ENTER YOUR CHOICE : 5
Exit
mythili@mythili:~$
RESULT:
15
DISPLAYING CURRENT DATE,USER NAME,FILE NAME AND DIRECTION
if [ "$ch" = 1 ]
then
echo "The Date is :"
date
sh pro4.sh
elif [ "$ch" = 2 ]
then
echo "The User Name is :"
who am i
sh pro4.sh
elif [ "$ch" = 3 ]
then
echo "Listing Files and Directories"
ls -l
sh pro4.sh
elif [ "$ch" = 4 ]
then
echo "Exit"
fi
16
OUTPUT
ythili@mythili:~$ nano display.sh
mythili@mythili:~$ chmod +x display.sh
mythili@mythili:~$ ./display.sh
1. DATE
2. USER NAME
3. LISTING FILES & DIRECTORIES
4. EXIT
Enter Your Choice : 1
The Date is :
Friday 26 March 2021 05:50:07 AM IST
Enter Your Choice : 2
The User Name is :
Mythili
nter Your Choice : 3
Listing Files and Directories
total 52
drwxr-xr-x 2 mythili mythili 4096 Feb 20 10:41 Desktop
-rwxrwxr-x 1 mythili mythili 410 Mar 26 05:59 display.sh
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Documents
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Downloads
-rwxrwxr-x 1 mythili mythili 1896 Mar 26 04:49 file.sh
drwxr-xr-x 4 mythili mythili 4096 Mar 26 05:39 Music
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Pictures
-rwxrwxr-x 1 mythili mythili 849 Mar 26 05:43 pipe.sh
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Public
-rw-rw-r-- 1 mythili mythili 0 Mar 26 05:37 sample1
-rw-rw-r-- 1 mythili mythili 0 Mar 26 05:23 sample2
-rwxrwxr-x 1 mythili mythili 626 Mar 26 05:10 system.sh
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Templates
drwxr-xr-x 2 mythili mythili 4096 Feb 19 23:04 Videos
-rw-rw-r-- 1 mythili mythili 25 Mar 26 04:52 xaa
Enter Your Choice : 4
17
Exit
mythili@mythili:~$
RESULT
18
FILTER COMMAND IN LINUX
if [ "$ch" = 1 ]
then
ls
echo "Enter the File Name : "
read a
echo "The File Content is : "
cat $a
echo "The Result is "
grep "file2" $a
sh pro5.sh
elif [ "$ch" = 2 ]
then
ls
echo "Enter the File Name : "
read a
echo "The File Content is : "
cat $a
echo "The File Contain the following No.of.Lines,Words & Characters :"
wc $a
sh pro5.sh
19
elif [ "$ch" = 3 ]
then
ls
echo "Enter the File Name : "
read a
echo "The File Content is :"
cat $a
echo "The Cut File Content is :"
cut -c1,3 $a
sh pro5.sh
elif [ "$ch" = 4 ]
then
ls
echo "Enter the File Name : "
read a
echo "The Content is : "
cat $a
echo "The Tr command Result is :"
cat $a|tr "[a-z]" "[A-Z]"
sh pro5.sh
elif [ "$ch" = 5 ]
then
echo "Exit"
fi
20
OUTPUT
ythili@mythili:~$ nano filter.sh
mythili@mythili:~$ ./filter.sh
1. GREP FILTER
2. WC FILTER
3. CUT FILTER
4. TR FILTER
5. EXIT
ENTER YOUR CHOICE : 1
esktop Documents file.sh Music pipe.sh sample1 system.sh Videos
display.sh Downloads filter.sh Pictures Public sample2 Templates xaa
Enter the File Name :
sample1
The File Content is :
welcome to linux program
ENTER YOUR CHOICE : 2
Desktop Documents file.sh Music pipe.sh sample1 system.sh Videos
display.sh Downloads filter.sh Pictures Public sample2 Templates xaa
Enter the File Name :
sample1
The File Content is :
welcome to linux program
The File Contain the following No.of.Lines,Words & Characters :
1 4 25 sample1
21
Wl
NTER YOUR CHOICE : 4
Desktop Documents file.sh Music pipe.sh sample1 system.sh Videos
display.sh Downloads filter.sh Pictures Public sample2 Templates xaa
Enter the File Name :
sample1
The Content is :
welcome to linux program
The Tr command Result is :
WELCOME TO LINUX PROGRAM
ENTER YOUR CHOICE : 5
Exit
mythili@mythili:~$
RESULT
22
REMOVING ZERO BYTE FILES
for i in *
do
if [ -f $i -a ! -s $i ]
then
rm $i
sleep 1
echo "$i file is Removed"
fi
done
ls
23
OUTPUT
RESULT:
24
SUM OF THE INDIVIDUAL DIGITS
while [ $n -gt 0 ]
do
a=$(($n%10))
n=$(($n/10))
sum=$(($sum+$a))
done
25
OUTPUT
RESULT:
26
GREATEST AMONG THE GIVEN NUMBERS
27
OUTPUT
RESULT:
28
PALINDROME CHECKING
if(( $flag==1))
then
echo "Input String is Palindrom"
fi
29
OUTPUT
mythili@mythili:~$ nano palin.sh
mythili@mythili:~$ chmod +x palin.sh
mythili@mythili:~$ ./palin.sh
Enter the String:
mam
Input String is Palindrom
Enter the String:
java
String is not palindrome
RESULT:
30
MULTIPLICATION TABLE
31
OUTPUT
32