Académique Documents
Professionnel Documents
Culture Documents
VI EDITOR, INODE
AND LINKS
Q11. CREATING
ARCHIVES
GZIP,GUNZIP,BZIP2,BUNZIP2,TAR
Q 12 Practice
Exercise 3
#!/bin/bash
hello()
{ a=`expr $c / $a`
D=`expr $b + $a`
echo "$D"
}
a=2
b=15
c=2
echo "a=$a b=$b c=$c"
hello
#!/bin/bash
hello()
{ a=`expr $c / $a`
e=`expr $b + $a`
D=`expr $e \* $b`
echo "$D"
}
a=3
b=10
c=9
echo "a=$a b=$b c=$c"
hello
9. Write a shell script to print all the users who have currently
logged in
#!/bin/bash
echo "the users logged in are ";w
10. Write a shell script to display only the size of files from the
current working directory
#!/bin/bash
ls -lah|awk '{print $5,$9}'|column –t
Q 13. Practice
Exercise 4
1. Write a shell script to create a directory and files and
subdirectories
#!/bin/bash
mkdir dummy
mkdir -pv dummy/demo/file.txt
#!/bin/bash
echo "enter two numbers"
read a b
if [ "$a" -gt "$b" ] #(($a>$b))
then
echo "$a is greater"
else
echo "$b is greater"
fi
else
echo "$a is odd"
fi
#!/bin/bash
echo "enter a environment variable in caps";read a
printenv $a
#!/bin/bash
Str=`echo $path`
F=${str:0:7}
Echo $F
#!/bin/bash
echo "enter 3 number"
read a b c
if [ $a -gt $b -a $a -gt $c ];
then
echo "$a is greatest"
elif [ $b -gt $c ];
then
echo "$b is greatest"
else
echo "$c is greatest"
fi
#!/bin/bash
var=$(date +%A)
echo $var
case "$var" in
("Monday") echo "Oh! its monday";;
("Tuesday") echo "3 more days to go";;
("Wednesday") echo "eagerly waiting";;
("Thursday") echo "just day left for an adventure";;
("Friday") echo "pack your bag";;
("Saturday") echo "fly away";;
("Sunday") echo "last day to have fun";;
esac
#!/bin/bash
echo "enter two numbers"
read a b
echo "enter your choice: \n 1.add \n 2.subtract \n 3. multiply \n 4. divide"
read c
case $c in
1) echo `expr $a + $b` ;;
2) echo `expr $a - $b` ;;
3) echo `expr $a \* $b` ;;
4) echo `expr $a / $b` ;;
esac
#!/bin/bash
echo "enter filename or directory"
read a
wc -lwm "$a"
#!/bin/bash
who|sort -k 3,3n
#!/bin/bash
echo "enter a year"
read a
while [ $a -ne 0 ]
do
if (($a%4==0));
then
echo "its a leap year"
else
echo "not a leap year"
fi
break;
done
#!/bin/bash
echo "enter a number"
read a
fact=1
while [ $a -ge 1 ]
do
fact=`expr $fact \* $a`
a=`expr $a - 1`
done
echo "factorial is $fact"
HOME,LANG,SHELL,USER,DISPLA
Y,VISUAL
Q 15. Concept of etc
dir. and special
permissions
/etc/passwd :-
/etc/shadow
Su :-
Suid :-
Sgid :-
Sticky bit :-
Q16. FILTER
COMMANDS
Aspell :-
Cut :-
Diff :-
Sort :-
Tail :-
Tr :-
Uniq :-
Wc :-
Awk :-
Q18.PRACTICLE
EXERCISE 5
1. Write a shell script to show following(Using Case construct)
#!/bin/bash
read a
ch=`echo $a | cut -c 1`
then
case $ch in
esac
case $dh in
esac
else
case $dh in
esac
fi
else
echo "not a prime number"
fi
else
f=`expr $f + 1`
fi
done
echo "even count = $e"
echo "odd count = $f"