Subscribe to Get Free Material Updates!
Visit my new blog WebData Scraping - Web Scraping Service provider company in India.

Write a script to implement the following commands Tree of DOS similar to which command 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
Output: 

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

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 

Output:

Write a script to display the date, time and a welcome message (like Good Morning etc.). The time should be displayed with “a.m.” or “p.m.” and not in 24 hours notation.

clear
HH=`date +%H`
time=`date +"%S %p"`
if [ $HH -ge 12 ];then
 HH=`expr $HH % 12`
 if [ $HH -lt 5 ];then
  msg="GOOD AFTERNOON"
 elif [ $HH -ge 5 ]  &&  [ $HH -lt 9 ];then
  msg="GOOD EVENING"
 else
  msg="GOOD NIGHT"
 fi
 echo "$msg ,CURRENT TIME $HH:$time"
 exit 1
else
 if [ $HH -lt 5 ];then
  msg="GOOD NIGHT"
 else
  msg="GOOD MORNING"
 fi
 echo "$msg ,CURRENT TIME $HH:$time"
 exit 1
fi

Output: 

Write a script to display the name of all executable files in the given directory.

clear
echo "Enter Directory Name:"
read dir
ls $dir>tempfile.txt
count=0
if [ -d $dir ];then
 for filename in `cat tempfile.txt`
 do
  if [ -x $filename ];then
   echo "$filename"
   count=`expr $count + 1`
  fi
 done
fi
echo "Total Executable Files Are $count"
rm tempfile.txt

Output: 

Write a script to display the name of those files (in the given Directory) which are having multiple links.

clear
echo "Enter Directory Name :="
read dir
len=`ls -l $dir | wc -l`
i=2
echo "File With Multiple Link are : "
echo " "
while [ $i -le $len ]
do
 record=`ls -l $dir | head -n $i | tail -n 1`
 filename=`echo $record | cut -d " " -f 9`
 link=`echo $record | cut -d " " -f 2`
 if [ $link -gt 1 ];then
  echo "$filename = $link"
 fi
 i=`expr $i + 1`
done

Output: 

Related Posts Plugin for WordPress, Blogger...

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes