Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Tuesday, 13 March 2012

Write a script to implement the following commands: Tree (of DOS) which (of UNIX)


echo "Enter path Name :="
read path
name=`find  "$path"  -print0 | xargs -0`
for i in $name
do
if [ -d $i ];then
echo $i>file.txt
count=`awk 'NF{print NF-1}' FS="/" file.txt`
format="|__"
temp=`expr $count + 1`
i=`echo $i|cut -d "/" -f $temp`
for (( j=0 ; $j < $count ; j=`expr $j + 1` ))
do
format="|    "$format
done
echo "$format$i"
fi
done

Write a script to display the directory in the descending order of the size of each file.


[[   METHOD 1   ]]

echo "ENTER DIR"
read dir
`echo ls -lS $dir` > file.txt
len=`cat file.txt | wc -l`
i=2
while [ $i -le $len ]
do
record=`ls -lS $dir | head -n $i | tail -n 1`
# record=`cat file.txt | head -n $i | tail -n 1`
filename=`echo $record | cut -d " " -f 9`
echo "$filename"
i=`expr $i + 1`
done

[[   METHOD 2   ]]


clear
echo "ENTER DIR"
read dir
`echo ls -lS $dir` > file.txt
len=`cat file.txt | wc -l`
i=2
echo "SIZE          FILENAME"
echo "====       ==============="
while [ $i -le $len ]
do
record=`ls -lS $dir | head -n $i | tail -n 1`
# record=`cat file.txt | head -n $i | tail -n 1`
filename=`echo $record | cut -d " " -f 9`
size=` echo $record | cut -d " " -f 5`
echo "$size        $filename"
i=`expr $i + 1`
done