Professional Documents
Culture Documents
Ans. $ls command allows you to view a list of the files and folders in a given directory.
example:diwaker@MyComputer:~/ubunlist$ ls
diwaker@MyComputer:~/ubunlist$ pwd
/home/diwaker/ubunlist
$tty #tty command of terminal basically prints the file name of the terminal connected to standard
input.
diwaker@MyComputer:~/ubunlist$ tty
/dev/tty1
example:diwaker@MyComputer:~$ cd ubunlist
diwaker@MyComputer:~/ubunlist$
Q2. Use the following commands: cal , cat(append), cat(concatenate), mv, cp, man, date?
exampel:diwaker@MyComputer:~/ubunlist$ cal
December 2021
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
#cat(append) add the data to the file without erasing existing data. And symbol is >>.
#cp stands for copy. This command is used to copy files or group of files or directory.
#man command isused to display the user manual of any command that we can run on the terminal
#Q3. Use the following command: chmod, grep, tput(clear, highlight) , bc?
#grep command searches a file for a particular pattern of characters, and displays all
example:diwaker@MyComputer:~/ubunlist$
#tput(clear, highlight) tput clear command clear the screen and tput highlight the text
#bc command is used for command line calculator. It is similar to basic calculator
#Q4.Write a shell script to check if the number entered at the command line Prime number or not?
#!\bin\bash
clear
for((i=2;i<=$n/2;i++))
do
if [ $((n%i)) -eq 0 ]
then
exit
fi
done
#!\bin\bash
clear
#Q6.Write a shell script to modify ‘cal’ command to display calenadars of the specified range of
month?
#!\bin\bash
clear
case $month1 in
JAN) m1=1;;
FEB) m1=2;;
MAR) m1=3;;
APR) m1=4;;
MAY) m1=5;;
JUN) m1=6;;
JUL) m1=7;;
AUG) m1=8;;
SEP) m1=9;;
OCT) m1=10;;
NOV) m1=11;;
DEC) m1=12;;
esac
month2=`echo $last | tr '[a-z]''[A-Z]'`
case $month2 in
JAN) m1=1;;
FEB) m2=2;;
MAR) m3=3;;
APR) m4=4;;
MAY) m5=5;;
JUN) m6=6;;
JUL) m7=7;;
AUG) m8=8;;
SEP) m9=9;;
OCT) m10=10;;
NOV) m11=11;;
DEC) m12=12;;
esac
then
else
set `date`
y=`echo $6`
fi
#Q7.Write a shell script to accept a login name. If not valid login name display message “Entered
login name is Inavlid”?
#!\bin\bash
top -u "$user"
else
fi
#!\bin\bash
now="$(date)"
#Q9.Write a shell script to display on the screen sorted output of “who” command along with total
number of users?
#!\bin\bash
clear
nuser=`who | wc -1`
who | sort
echo "--------------------"
#!\bin\bash
while [ $c -le 10 ]
do
m=$((x * c))
c=$((c + 1))
done
#Q11.Write a shell script to compare two files and if found equal asks the user to delete the
duplicate file?
#!\bin\bash
echo "Compare two files and if found equal then remove the dublicate file..."
then
echo "same"
rm -i -- "$file2"
else
fi
#!\bin\bash
sum=0
if [ $n -lt 0 ]
then
else
while [ $n -gt 0 ]
do
k=$(( $n % 10 ))
n=$(( $n / 10 ))
sum=$(( $k + $sum ))
done
fi
#Q13.Write a shell script to merge the contents of three files, sort the contents and then display
them page by page?
#!\bin\bash
out="outputs.$$"
count=0
if [ $# -ne 3 ]
then
exit 1
fi
if [! -f $file1 ]
then
exit 2
fi
if [! -f $file2 ]
then
exit 3
fi
if [! -f $file3 ]
then
exit 4
fi
#Q14.Write a shell script to find the LCD (least common divisor) of two numbers?
#!\bin\bash
if [ $a -gt $b ]
then
num=$a
den=$b
else
num=$b
den=$a
fi
while [ $r -ne 0 ]
do
num=$den
den=$r
done
rev=$den
lcd=`expr $a \* $b / $rev`
#!/bin/bash
echo"CALCULATOR"
while :
do
read option
case $option in
6) echo "Quit..."
exit;;
esac
done
#!\bin\bash
#!\bin\sh
f=1
while [ $n -gt 1 ]
do
f=$((f * n))
n=$((n - 1))
done
#!\bin\bash
a=0
b=$n
while [ $n -ne 0 ]
do
dig=$(( $n % 10 ))
a=$(($a + $dig*dig*dig ))
n=$(($n / 10))
done
if [ $a -eq $b ]
then
else
echo " It is not a armstrong "
fi
!\bin\bash
echo "To check whether the file have all permission or not..."
if test -f "$fname"
then
then
ls -l $fname
fi
else
fi
#!\bin\bash
do
do
then
echo -n "*"
else
done
do
echo -n "*"
done
echo -e "\n"
done