Write a shell script to delete zero sized files from a given directory (and all its sub-directories)
clear
echo "Enter Dirctory : \c"
read dir1
# check inputed name is directory or not
if [ ! -d $dir1 ]
then
echo "DIRECTORY [ $dir1 ] NOT EXIST"
exit 1
fi
#nevigate to given directory
cd $dir1
# create list of element we have in inputed directory
`echo ls`>fileList
#counter for sub directory
d=0
#counter for zero sized file
f=0
for fileName in `cat fileList`
do
if [ ! -d $fileName ]
then
#find the size of file
size=`ls -s $fileName`
size=`echo $size|cut -d " " -f 1`
if [ $size -eq 0 ]
then
f=`expr $f + 1`
rm $fileName
fi
else
# delete sub directory
d=`expr $d + 1`
rm -r $fileName
fi
done
t=`expr $f + $d`
echo "Total Deleted element : "$t
echo "Total Deleted file : "$f
echo "Total Deleted Sub directory : "$d
Labels:
shell script
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
 - Mobile Computing-4649303 Practical Solution
 - Android Programming New Syllabus Theory
 - PHP LAMP Question Bank
 - PHP LAMP Theory
 - Step by Step Android Example
 - Android Practical
 - Android Theory
 - Android Question Bank
 - Networking FON Practical
 - Networking FON Theory
 - OS Practical
 - OS Theory
 - HTML
 - JavaScript
 - J2EE WTAD Theory
 - J2EE WTAD Question Bank
 - J2EE WTAD Quick Guide
 - J2EE WTAD GTU Papers
 - J2EE WTAD Practical
 - Python
 - JAVA Theory
 - JAVA Practical
 - MIS
 
Categories
- Android (55)
 - CSS (3)
 - Configure Tomcat7 (2)
 - Decryption (16)
 - Difference (1)
 - Encryption (16)
 - Error Detection and Correction Techniques (3)
 - FON (27)
 - Framing Technic (2)
 - J2EE (29)
 - JAVA (13)
 - JavaScript (19)
 - OS (17)
 - PHP (11)
 - Protocol (3)
 - SERVER SOCKET PROGRAMING (7)
 - Servlet (13)
 - WTAD (34)
 - c (11)
 - install Tomcat (2)
 - linux (8)
 - shell script (33)
 - unix (22)
 
Blog Archive
- 
        ▼ 
      
2012
(79)
- 
        ▼ 
      
September
(22)
- Chapter 7, Memory Management
 - Chapter 6, Concurrency: Deadlock and Starvation
 - Chapter 5, Concurrency: Mutual Exclusion and Sync...
 - Chapter 4, Threads, SMP, and Micro kernels
 - Chapter 3, Process Description and Control
 - Chapter 2, Operating System Overview
 - Chapter 1, Computer System Overview
 - menu in android tutorial
 - android animation example
 - android chronometer example
 - spinner in android example
 - listview in android
 - implicit intent in android example
 - addTextChangedListener in Android example
 - Be a Freelances and earn $$$$
 - View SQLite Database
 - Write a shell script to delete zero sized files fr...
 - Android Intent Example
 - Hello World in Android
 - SQLite Android Tutorial
 - Happy Teachers' Day
 - Thank you GOD
 
 
 - 
        ▼ 
      
September
(22)
 
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
This definition can also be implemented in this way also.....
clear
# c character (unbuffered) special
#f regular file
for i in `find /home/student/Desktop/OS-2 -type f -size 0c`
do
echo "$i has Zero size File"
echo `rm $i`
done
Post a Comment