====================================================================
#!/bin/bash
#
read -p "Please type in your Dir:" DIR
cd $DIR &> /dev/null
until [ $? -eq 0 ] ; do
echo "There is something wrong with your Dir.Please try agin."
read -p "Please type in your Dir:" DIR
cd $DIR &> /dev/null
done
echo "Testing.Please wait for a while."
ls $DIR -l |grep ".*" |grep "^total 0" &> /dev/null
if [ $? -eq 0 ]; then
echo "There is no such a file."
exit 0
else
ls -l $DIR
echo "Do you want to remove these files?"
fi
while true; do
read -p "Please type in (y/n):" TY
case $TY in
y)
rm -rf $DIR/*
exit 0
;;
n)
echo "Thank goodness"
exit 2
;;
*)
echo "There is something wrong.Please type agin."
;;
esac
done
======================================================================
说明: 由于时间仓促,这个脚本写的并不完善.
1.输入的路径必须为绝对路径!!
2.删除为直接删除 请慎用!!
3.指定路径下不论是普通文件还是其他类型文件,包括目录全部当做文件看待.
(不了解问题中的"文件"具体指的是哪一类文件)
4.经过多次测试,可直接拷贝使用而不需修改. (前提:使用bash shell)
5.由于英文能力有限,脚本中部分提示语或有语意不明之处.
取消
评论