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的多功能聊天室 其实这个项目在我电脑已经躺了多时,最初写完项目规划后,我就认认真真地去实现了它,后来拿着这个项目区参加了面试,同样面试官也拿这个项目来 ...
随机推荐
- 本地推送UILocalNotification的一些简单方法
1.添加本地推送,需要在app添加推送.可以根据通知的userInfo的不同的键值对来区分不同的通知 UILocalNotification *notification = [[UILocalNoti ...
- go语言中的反射reflect
package main; import ( "fmt" "reflect" ) //反射refection //反射使用TypeOf和ValueOf函数从接口 ...
- Python中setup.py一些不为人知的技巧
http://python.jobbole.com/80912/ 在我开始之前,我想先说清楚我将要解释的是些“窍门”.他们不是“最好的做法”,至少在一种情况下是不可取的. 说到不可取的做法,我会适时写 ...
- 转:css知多少(1)——我来问你来答
1. 引言 各位前端或者伪前端(比如作者本人)的同志们,css对你们来说不是很陌生.比如我,在几年之前上大学的时候,给外面做网站就用css,而且必须用css.这样算下来也得六年多了,有些功能可能轻车熟 ...
- PAT 1038 统计同成绩学生(20)(代码)
1038 统计同成绩学生(20)(20 分) 本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入格式: 输入在第1行给出不超过10^5^的正整数N,即学生总人数.随后1行给出N名学生 ...
- 如何搭建http服务仓库
1.拷贝仓库repo-A文件到服务器/media/D: 2.通过createrepo_c 生成仓库rpm信息数据 cd repo-A createrepo . 3.chmod -R 775 repo ...
- collectionView 防止cell复用的方法
collectionView 防止cell复用的方法 一: //在创建collectionView的时候注册cell(一个分区) UICollectionViewCell *cell=[collect ...
- mysql 优化之一
提升速度 show variables like 'innodb_flush_log_at_trx_commit'; 会显示为1 set global innodb_flush_log_at_trx ...
- Ubuntu安装bcmath扩展
sudo apt-get install php-bcmath
- JSP脚本元素(声明 %! 表达式 %= 脚本 %)
JSP脚本元素包括声明.表达式.脚本 声明(declaration):用于在JSP页面中声明合法的变量和方法.以“<%!”开始,以“%>”结束. 在JSP页面中,一个声明可以出现在任何地方 ...