• shell-自定义rm


    <<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
  • 相关阅读:
    CentOS7配置VIP
    Linux定时任务crontab命令
    zabbix安装部署
    ansible部署EFK
    Python中参数的冒号与箭头表示注释
    pycharm 进行远程服务器修改与调试
    判别模型与生成模型
    写Python机器学习时的一些注意事项
    numpy基本操作
    手写神经网络
  • 原文地址:https://www.cnblogs.com/watchslowly/p/9742504.html
Copyright © 2020-2023  润新知