shell实现linux回收站的功能
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回收站的功能的更多相关文章
- Linux学习笔记(15)shell基础之Bash基本功能
1 shell概述 shell是一个命令解释器,为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序.用户可以用shell启动.挂起.停止甚至是编写一些程序. shell是一个功能强大 ...
- linux shell 和linux 命令的区别?windows shell 和 windows 命令呢?
shell翻译成壳的意思,它是包裹在linux内核外层的,一个可通过一系列的linux命令对操作系统发出相关指令的人机界面. shell可以通过其条件语句和循环语句等,把一系列linux命令结合在一起 ...
- 打造Linux回收站
linux是没有回收站概念的,一旦误删除文件了是很难很难找回来的,对普通用户而言误删除文件就等于永久性不可逆丢失数据了:不过可以改造一下rm命令来变相实现回收站功能,实际上就是mv命令转移文件到指定路 ...
- shell在linux里摇摇晃晃
1.shell不只是一种解释器,还是一种编程工具 查看系统中可用的shell,linux默认使用 Bash Shell [root@localhost ~]# cat /etc/shells /bin ...
- 利用shell脚本实现计划任务功能 V1.2
2013.05.10 mytask 1.2 主程序休眠时间分成若干小的时间片断分段休眠,避免长时间的休眠不能及时响应系统信号. 2013.05.07 mytask 1.1 昨天发布了mytask1. ...
- 【Microsoft Azure 的1024种玩法】六、使用Azure Cloud Shell对Linux VirtualMachines 进行生命周期管理
[文章简介] Azure Cloud Shell 是一个用于管理 Azure 资源的.可通过浏览器访问的交互式经验证 shell. 它使用户能够灵活选择最适合自己工作方式的 shell 体验,本篇文章 ...
- linux回收站设计
linux回收站设计 在windows下有一个很好的东西,那就是回收站,虽然有很多人批评它.linux不是没有回收站,很多桌面环境都可以看到是有回收站的. 这里是讨论如何设计一个回收站,而不是有没有的 ...
- 分享:shell去掉linux配置文件的注释行
如何通过shell去掉Linux配置文件中的注释行呢? 本文给出两种解决方法,供大家参考. 方法1.使用grep -v "^#" 来去掉注释行,其中:-v 表示取反 ^# 表示注解 ...
- 基于LINUX的多功能聊天室
原文:基于LINUX的多功能聊天室 基于LINUX的多功能聊天室 其实这个项目在我电脑已经躺了多时,最初写完项目规划后,我就认认真真地去实现了它,后来拿着这个项目区参加了面试,同样面试官也拿这个项目来 ...
随机推荐
- pyinstller的安装
下载:http://www.pyinstaller.org/ 解压到目录 切换到python目录 执行命令: python.exe D:\Download\PyInstaller-2.1\setup. ...
- MVC与WebApi中的异常统一处理
1.简单例子 /// <summary> /// 全局页面控制器异常记录 MVC的异常处理 /// </summary> public class CustomErrorAtt ...
- JSON与GSON比较
JSON: 是Android SDK官方的库,所以在开发移动端的工程时就必须使用JSON.进行数据的转换和处理 GSON: GSON适用于服务端,gson比json功能更加强大.比如在集合类的处理.自 ...
- VSS源代码管理器运行代码分析工具的命令
当你发现代码库总是报需要联系管理员运行代码分析工具时,你可以使用命令分析代码库代码解决: To fix the database problems, you can restart the analy ...
- python 网络下载的三种风格 未完成
import osimport timeimport sys import requests#依序下载POP20_CC = ('CN IN US ID BR PK NG BD RU JP' 'MX P ...
- 在myeclipse中修改发布到tomcat的项目目录名称
在项目上右键-->Properties 搜索web-->Project Facets(Web) 更改右侧Web Content-root的信息
- Junit4知识梳理
一.junit官网 junit4:http://junit.org/junit4/ junit5:http://junit.org/junit5/ 二.github junit4: https://g ...
- PAT 1066 图像过滤(15)(代码)
1066 图像过滤(15 分) 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: ...
- *jquery操作DOM总结 (原创:最全、最系统、实例展示)
jquery操作DOM包括八个方面: 一:jquery对DOM节点的基本操作:二:jquery对DOM节点的CSS样式操作:三:jquery遍历DOM节点:四:jquery创建DOM节点:五:jque ...
- 手机端适配方案 媒体查询和flexbale
方法一 flexible 一.npm 包安装 lib-flexible 淘宝适配方案 px2rem px自动转rem npm install lib-flexible --save npm insta ...