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的多功能聊天室 其实这个项目在我电脑已经躺了多时,最初写完项目规划后,我就认认真真地去实现了它,后来拿着这个项目区参加了面试,同样面试官也拿这个项目来 ...
随机推荐
- SideBar 选择城市时右侧边上的 选择bar
需要定义一个SideBar的视图类 在布局文件中引用 同时在布局中设置一个textView默认不可见 当触摸时才显示 在调用的Activity中 sideBar.setOnTouchingL ...
- Non-negative Integers without Consecutive Ones
n位二进制,求不包含连续1的二进制(n位)数字个数. http://www.geeksforgeeks.org/count-number-binary-strings-without-consecut ...
- 14.Mysql事务控制和锁定
14.事务控制和锁定存储引擎和锁: MyISAM和MEMORY存储引擎的表支持表级锁: BDB存储引擎的表支持页级锁: InnoDB存储引擎的表支持行级锁.默认情况下,表锁和行锁都是根据执行的语句自动 ...
- C# 切换到二级域名,使用Cookie
之前的网站一直用的是一级域名,现因为其他原因,需要使用一个二级域名访问,原先的域名不用了. 使用二级域名后,发现Cookie一直取不到,分析代码发现,原来是需要在设置cookie的时候,把二级域名加上 ...
- 使用开源的工具解析erspan流量
Decapsulation ERSPAN Traffic With Open Source Tools Posted on May 3, 2015 by Radovan BrezulaUpdated ...
- (O)web缓存
为什么要用缓存 一般针对静态资源如CSS,JS,图片等使用缓存,原因如下: 请求更快:通过将内容缓存在本地浏览器或距离最近的缓存服务器(如CDN),在不影响网站交互的前提下可以大大加快网站加载速度. ...
- linux以16进制方式查看文件
vim打开文件 :%!xxd 以16进制查看 :%!xxd -r 转回来
- 大神你好,可以帮我P张图吗?
韩国版的求大神帮我P张图,看得有点下巴脱臼啊!哈哈哈哈哈哈哈~ 感觉照片拍得很尴尬,请大神P得更有动感 拍了跳跃照片,但内衣露出来一点,能帮忙去掉吗 不喜欢没穿制服的样子,请帮忙加上制服 希望背景 ...
- Python之路(第二篇):Python基本数据类型字符串(一)
一.基础 1.编码 UTF-8:中文占3个字节 GBK:中文占2个字节 Unicode.UTF-8.GBK三者关系 ascii码是只能表示英文字符,用8个字节表示英文,unicode是统一码,世界通用 ...
- Split Array Largest Sum LT410
Given an array which consists of non-negative integers and an integer m, you can split the array int ...