Hi,
I am trying to write a script that will use ls on a directory and list the files one at a time and their size. If the size is 0 i want it to ask me if I want to delete it (yes or no). If I say yes, I want it to delete but it won't know what the file name is just from running from the script. First I just cannot get it to display the name before the size.
This is what I have:
dirname=$1
clear
if [ $# -ge 2 ]; then
echo "Too many parameters. Usage: file-info [directory]"
exit
elif [ $# -eq 0 ];then set `pwd`;
fi
if [ -d $1 ]; then
cd $1
echo "Processing `pwd`... "
ls -1 -s
if [ -filesize=0- ]; then
echo "Would you like to delete this file? (y/n)"
read ANSWER
if [ $ANSWER = "y" ]; then
rm -filename-
elif [ $ANSWER = "n" ]; then
echo "...proceed..."
fi
fi
cd
else
echo "$1 is not a valid directory... terminating..."
fi
Can someone please give me a hand with this? Thank you.