zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Vue中调用另一个组件中自定义事件
    docker下安装MySQL
    docker下安装Redis
    .NET Core简介
    Object(Asp.NET核心机制内置对象汇总)
    .NET MVC5简介(六)HttpHandler
    .NET MVC5简介(五)管道处理模型IHttpModule
    hibernate有什么作用
    hibernate编写时没有提示
    触发器insert
  • 原文地址:https://www.cnblogs.com/watchslowly/p/9742504.html
Copyright © 2011-2022 走看看