Linux

Delete Zero Files Size

23-Jul-2009 00:43:42

This aught to get you started.
It just list the files and size in the /home/images folder.
You will have to add some more stuff for deleting.
If you want to make a couple of empty files to help in testing,
the easiest way is use the command: >
For example: >file.txt

Edit: you could test for more than one argument with this...
test $# == 1 || usage

Code:
#!/bin/bash
# Example: ./test /home/images

usage()
{
echo "Usage: $0 Directory_Name"
exit 1;
}

test -d "$1" || usage

for i in `ls $1/*` ; do
size=`stat -c %s $i`

if [ $size -lt 1 ]; then
echo "$i is $size ( This one is empty ) "
else
echo "$i is $size "
fi

done

 

My 2¢ worth.. Unelegant but works.

Quote:

##/bin/bash

dir_to_clean=$1

cd $1
ls -1s |awk '{if ($1==0) print ("rm -f "$2)}' > rmscript
chmod +x rmscript
echo "The following files with zero size will be removed:"
cat rmscript


echo -n "Proceed? [Y/N]: "
read response
if [ "$response" == "Y" ]; then
rmscript
fi

rm -rf rmscript

 


 Reply Comment
 
  qmetawlw ( 18-Oct-2009 16:17:45 )

<a href="http://ndlvybgj.com">pjgnjumw</a>  ahowfltk http://jeqbdsan.com abgkzljv upsdomib  [URL=http://fdqaccjv.com]cumtboel[/URL]

 
Your name
Website http://
Comment
   
Image verification code
Retype image code here