<<COMMENT 功能介绍: 1.删除操作执行前先获取文件或目录的大小,然后对比系统中的磁盘空间 2.如果有多余空间,则创建对应的隐藏目录,并备份 3.如果没有足够的空间,可以提醒用户是否放弃备份,如果放弃,则直接删除 COMMENT filename=$1 d=`date +'%Y%m%d%H%M'` f_size=`du -sk $1|awk '{print $1}'` disk_size=`LANG=en; df -k |grep -iv filesystem |awk '{print $4}' |sort -n |tail -n 1` big_filesystem=`LANG=en; df -k |grep -iv filesystem |sort -n -k4 |tail -n 1 |awk '{print $NF}'` if [ $f_size -lt $disk_size ]; then read -p "Are U sure delete the file or directory $1 y|n:" c if [ $c=="y" ] || [ $c=="Y" ]; then mkdir -p $big_filesystem/.$d && rsync -aR $1 $big_filesystem/.$d/ && /bin/rm -rf $1 elif [ $c=="n" ] || [ $c=="N" ]; then exit 0 fi else echo "The disk size is not enough to backup the files $1" read -p "Do you want to delete "$1"? y|n:" c if [ $c=="y" ] || [ $c=="Y" ]; then echo "It will delete "$1" after 5 seconds whitout backup" for i in `seq 1 5`; do echo -ne "."; sleep 1;done echo /bin/rm -rf $1 elif [ $c=="n" ] || [ $c=="N" ]; then echo "It will not delete $1." exit 0 else echo "Please input 'y' or 'n'" fi fi