Linux Programs
Linux Programs
No : 1
FILE COMMANDS IN LINUX
Aim
To write a shell script to stimulate the file commands: rm, cp, cat, mv, cmp, wc, split, diff.
Algorithm
Coding
1
sh f1.sh
elif [ "$ch" = 2 ]
then
echo "DISPLAY"
ls
echo "Enter the File Name to be Display"
read a
cat $a
sh f1.sh
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
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
2
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
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
3
Ex.No : 2
SYSTEM CONFIGURATION DETAILS
Aim
Algorithm
Step 1: Start the Program
Step 2: Display the User name using user command.
Step 3: Display Log name using logname command.
Step 4: Display current shell using shell command.
Step 5: Display home directory using home command.
Step 6: Display operating system type using ostype command.
Step 7: Display current path using path command.
Step 8: Display current working directory using pwd command.
Step 9: Display current logged no.of users using who command.
Step 10: Display available shells using /etc/shells command.
Step 11: Display CPU information using grep "model name" /proc/cpuinfo
command.
Step 12: Display Memory information using vmstat.
Step 13: Stop the program.
Coding
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
4
Ex.No : 3
PIPES, REDIRECTION AND TEE COMMANDS
Aim
To write a Shell Script to implement the following: pipes, Redirection and tee commands.
Algorithm
Coding
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"
5
read file2
cat $file1 >> $file2
echo "Content of File1"
cat $file1
echo "Content of File2"
cat $file2
sh pro3.sh
elif [ "$ch" = 4 ]
then
ls
echo "Enter the File Name"
read file1
cat $file1 | tee temp
echo "Content of Temp"
cat temp
sh pro3.sh
elif [ "$ch" = 5 ]
then
echo "Exit"
fi
6
Ex.No : 4
Aim
To write a shell script for displaying current date, user name, file listing and directories by
getting user choice.
Algorithm
Coding
7
Ex.No : 5
FILTER COMMANDS IN LINUX
Aim
Algorithm
Coding
8
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
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
9
Ex.No : 6
REMOVING ZERO BYTE FILES
Aim
To write a shell script to remove the files which has file size as zero bytes.
Algorithm
Coding
for i in *
do
if [ -f $i -a ! -s $i ]
then
rm $i
sleep 1
echo "$i file is Removed"
fi
done
ls
10
Ex.No : 7
SUM OF THE INDIVIDUAL DIGITS
Aim
To write a shell script to find the sum of the individual digits of a given number.
.
Algorithm
11
Ex.No : 8
GREATEST AMONG THE GIVEN NUMBERS
Aim
To write a shell script to find the greatest among the given set of numbers using command
line arguments.
.
Algorithm
Coding
n=$#-1
big=$1
for((x=1;x<=n;x++))
do
if [ $big -lt $2 ]
then
big=$2
fi
shift
done
echo "The Biggest Number is $big"
12
Ex.No : 9
PALINDROME CHECKING
Aim
Algorithm
Coding
clear
echo "Enter the String"
read str
len=${#str}
flag=1
for((i=0;i<=len/2;i++))
do
c1="${str:$i:1}"
c2="${str:$len-$i-1:1}"
if [ $c1 != $c2 ]
then
flag=0
echo "String is not palindrome"
break
fi
done
if(( $flag==1))
then
echo "Input String is Palindrom"
fi
13
Ex.No : 10
MULTIPLICATION TABLE
Aim
To write a shell script to print the multiplication table of the given argument using for loop.
.
Algorithm
Coding
clear
echo "Enter the Row Value :"
read r
echo "Enter the Table Value :"
read n
for((x=1;x<=r;x=x+1))
do
echo "$x * $n = $(($x*$n))"
done
14