shell实现linux回收站的功能

下载:

https://gitee.com/LoongWang/shellrecycling/repository/archive/master.zip

代码:

 #/usr/bin/env bash

 #定义
 #定义回收站目录
 RecyclingDir='/usr/local/recycling/'
 #定义回收站log文件夹
 RecyclingLogDir='/var/log/recyclinglog/'
 #定义回收站log文件
 RecyclingLog="/var/log/recyclinglog/$(whoami)"
 #定义回收站家目录
 UserRecyclingDir="/usr/local/recycling/$(whoami)"
 #定义返回码
 ReturnCode=

 #程序开始
 #检测主文件是否存在、没有则新建

 for DirName in $RecyclingLogDir $RecyclingDir $UserRecyclingDir
 do
     if [ ! -d $DirName ]
     then
         if [[ $DirName == "$RecyclingLogDir" ]]
         then
             mkdir $RecyclingLogDir
              $RecyclingLogDir
             continue
         fi
         #将Log写入文件中
         echo "$(date +"%F %H:%M:%S") - Make Dirctory" >> $RecyclingLog
          $RecyclingLog
         #创建目录
         mkdir $DirName

          ]
         then
             echo "$(date +"%F %H:%M:%S") - Make Dirctory $DirName Ok" >> $RecyclingLog
         else
             echo "$(date +"%F %H:%M:%S") - Make Dirctory $DirName Fail" >> $RecyclingLog
             echo "$(date +"%F %H:%M:%S") - Make Dirctory Fail"

             ReturnCode=
             echo -e "The Linux Comamnd is error , returncode:127\n"
             echo "$(date +"%F %H:%M:%S") - Make Dirctory Fail"
             echo "Your can see log the $RecyclingLog" 

             exit $ReturnCode
         fi
          $DirName

         if [[ $DirName == $UserRecyclingDir ]]
         then
              $DirName
         fi

     fi
 done

 #移动目录至回收站
  ]
 then
     echo "Usage:$0 file1 file2 file3 ..."
     ReturnCode=
 else
     #循环开始
     for DelFile in $@
     do
         #判断是否存在文件
         if [ -e $DelFile ]
         then
             echo -e "\n$(date +"%F %H:%M:%S") - Delete $DelFile" >> $RecyclingLog

             mv $DelFile $UserRecyclingDir/$(date +"%F:%H:%M:%S")-$DelFile

             #判断命令是否执行成功
              ]
             then
                 #命令执行成功
                 echo -e "\n$(date +"%F %H:%M:%S") - Delete $DelFile - OK" >> $RecyclingLog
                 echo -e "$(date +"%F %H:%M:%S") - Delete $DelFile - OK"
             else
                 #命令执行失败
                 echo -e "\n$(date +"%F %H:%M:%S") - Delete $DelFile - Fail" >> $RecyclingLog
                 echo -e "\n$(date +"%F %H:%M:%S") - Delete $DelFile - Fail"
                 ReturnCode=
             fi
         else
             #不存在文件
             echo -e "\n$(date +"%F %H:%M:%S") - $DelFile is not exists" >> $RecyclingLog
             echo -e "\n$(date +"%F %H:%M:%S") - $DelFile is not exists"
             ReturnCode=
         fi
     done

     exit $ReturnCode
 fi
 #!/usr/bin/env bash

 RecyclingDir="/usr/local/recycling"
 AudoDelRecyclingLog="/var/log/auto_del_recycling.log"
 errorlog="error.log"

  ]
 then
     for DirName in `ls $RecyclingDir`
     do
         if [ -d $RecyclingDir\/$DirName ]
         then
                 for FileName in `ls $RecyclingDir\/$DirName`
                 do

                         NowDate=$(date +"%s")
                         GetFile=$(stat -c %X $RecyclingDir\/$DirName\/$FileName)
                         DifferTime=$(echo "value=0;$NowDate - $GetFile" | bc)

                          ]
                         then
                                 echo -e "$(date +"%F_%H:%M:%S")-Deleteing $RecyclingDir $DirName(type $DirName is:$(file $RecyclingDir\/$DirName\/$FileName))" >> $AudoDelRecyclingLog
                                 rm -rf $RecyclingDir\/$DirName\/$FileName
                                 echo -e "$(date +"%F_%H:%M:%S")-Deleted $RecyclingDir $DirName $FileName OK" >> $AudoDelRecyclingLog
                         fi
                 done

         else
                 echo -e "$(date +"%F_%H:%M:%S")-$DirName is not dirctory(type $DirName is:$(file $RecyclingDir\/$DirName))" >> $AudoDelRecyclingLog
         fi
     done
 else
         echo -e "$(date +"%F_%H:%M:%S")-The User ID is not root,please login root exec(uid:`id -u`)" >> $errorlog
 fi

shell实现linux回收站的功能的更多相关文章

  1. Linux学习笔记(15)shell基础之Bash基本功能

    1 shell概述 shell是一个命令解释器,为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序.用户可以用shell启动.挂起.停止甚至是编写一些程序. shell是一个功能强大 ...

  2. linux shell 和linux 命令的区别?windows shell 和 windows 命令呢?

    shell翻译成壳的意思,它是包裹在linux内核外层的,一个可通过一系列的linux命令对操作系统发出相关指令的人机界面. shell可以通过其条件语句和循环语句等,把一系列linux命令结合在一起 ...

  3. 打造Linux回收站

    linux是没有回收站概念的,一旦误删除文件了是很难很难找回来的,对普通用户而言误删除文件就等于永久性不可逆丢失数据了:不过可以改造一下rm命令来变相实现回收站功能,实际上就是mv命令转移文件到指定路 ...

  4. shell在linux里摇摇晃晃

    1.shell不只是一种解释器,还是一种编程工具 查看系统中可用的shell,linux默认使用 Bash Shell [root@localhost ~]# cat /etc/shells /bin ...

  5. 利用shell脚本实现计划任务功能 V1.2

    2013.05.10  mytask 1.2 主程序休眠时间分成若干小的时间片断分段休眠,避免长时间的休眠不能及时响应系统信号. 2013.05.07 mytask 1.1 昨天发布了mytask1. ...

  6. 【Microsoft Azure 的1024种玩法】六、使用Azure Cloud Shell对Linux VirtualMachines 进行生命周期管理

    [文章简介] Azure Cloud Shell 是一个用于管理 Azure 资源的.可通过浏览器访问的交互式经验证 shell. 它使用户能够灵活选择最适合自己工作方式的 shell 体验,本篇文章 ...

  7. linux回收站设计

    linux回收站设计 在windows下有一个很好的东西,那就是回收站,虽然有很多人批评它.linux不是没有回收站,很多桌面环境都可以看到是有回收站的. 这里是讨论如何设计一个回收站,而不是有没有的 ...

  8. 分享:shell去掉linux配置文件的注释行

    如何通过shell去掉Linux配置文件中的注释行呢? 本文给出两种解决方法,供大家参考. 方法1.使用grep -v "^#" 来去掉注释行,其中:-v 表示取反 ^# 表示注解 ...

  9. 基于LINUX的多功能聊天室

    原文:基于LINUX的多功能聊天室 基于LINUX的多功能聊天室 其实这个项目在我电脑已经躺了多时,最初写完项目规划后,我就认认真真地去实现了它,后来拿着这个项目区参加了面试,同样面试官也拿这个项目来 ...

随机推荐

  1. HTML转义字符 Unicode和CSS伪类介绍

    CSS 伪类用于向某些选择器添加特殊的效果. a:link {color: #FF0000} /* 未访问的链接 */ a:visited {color: #00FF00} /* 已访问的链接 */ ...

  2. (IOS可自动播放)使用bxslider做了一个切换图片跟随播放MP3的功能

    代码: <!DOCTYPE html> <html lang="zh-Hans"> <head> <meta charset=" ...

  3. c# 24种设计模式4建造者模式(Builder)

    先来一个例子 建造者接口 public interface IBuilder { void CreateLogo(); void CreateBody(); void CreateWheel(); v ...

  4. opencv 形态学操作应用-提取水平与垂直线

    adaptiveThreshold(~gray_src, binImg, , ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, , -); #include <ope ...

  5. android如何判断控件的显示或者隐藏

    可以利用Android view getVisibility()的值来实现,具体如下: (1)0 -------- VISIBLE 可见(1)4 -------- INVISIBLE 不可见但是占用布 ...

  6. P<0.05就够了?还要校正!校正!3个方法献上

    P<0.05就够了?还要校正!校正!3个方法献上 (2017-01-03 17:55:12) 转载▼   分类: 数理统计 (转  医生科研助手 解螺旋 微信公众号)   当有多组数据要比较时, ...

  7. 应用内直接跳转到Appstore

    iOS开发中,应用内直接跳转到Appstore .进入appstore中指定的应用 NSString *str = [NSString stringWithFormat: @"itms:// ...

  8. sscanf 解析字符串

    test.txt中内容如下所示: eth0||192.168.0.2-192.168.0.150 eth2||192.168.0.2-192.168.0.150 想要将其中的ip地址等解析出来: #i ...

  9. JSON中的{}与[]的区别

    []:索引数组 {}:关联数组(js中,即对象)

  10. Linux安装及入门

    Linux安装及学习 Linux遇到的问题: 在安装过程中因为代码输错(少空格)而质疑自己下载的ubuntu和virtualbox版本,于是卸载之后重新安装了一次,后来才发现是代码输错了(教程中的空格 ...