Monday, January 20, 2014

Unix and Shell Programming - List and Delete Zero Bytes File

with 0 Comment
while true
do
echo "Menu"
echo "------"
echo "1.List the zero byte files"
echo
echo "2.Delete the zero byte files"
echo
echo "3.Exit"
echo
echo "Enter your choice"
read ch
case $ch in

1)
echo "List of Zero byte files"
echo "---------------------"
echo
flag=0
for i in*
do
if[-f $i -a ! -s $i]
then
ls -l $i
flag=1
fi
done
if[$flag=0]
then
echo "No Zero bytes files"
echo
fi
;;

2)
echo "Delete the zero bytes files"
echo "--------------------------"
echo
flag=0
for i in*
do
if[-f $i -a ! -s $i]
then
rm -i $i
flag=1
fi
done
if[$flag=0]
then
echo "No Zero bytes for Information"
echo
fi
;;

3)
echo "Exit"
exit
;;
esac
done

-----------
OUTPUT:
-----------
Menu
------
1.List the zero byte files
2.Delete the zero byte files
3.Exit

Enter your choice
1

List of zero byte choice
------------------------
-rw-rw-r--  1  smca13   smca13    0 Sep 26  15:17  count1
-rw-rw-r--   1 smca13   smca13    0 Oct 11  16:43  qyes
-rwxrwxrwx    1 smca13  smca13    0 Jan 30   2010  rithika
---x--x--x    1  smca13   smca13  0 Jan 30   2010  viji

Enter your choice
2

Delete the Zero bytes files
---------------------------
rm:remove regular empty file 'count1'?n
rm:remove regular empty file 'qyes'? y
rm:remove regular empty file 'rithika'?n
rm:remove write-protected regular empty file 'viji'?n

Enter your choice
1

List of Zero byte files
----------------------
-rw-rw-r--    1   smca13   smca13    0 Sep 26 15:17  count1
-rwxrwxrwx   1  smca13     smca13    0 Jan 30   2010  rithika
--x--x--x      1 smca13    msca13    0 Jan 30    2010 viji

Enter your choice
3
Exit

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive