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的多功能聊天室 其实这个项目在我电脑已经躺了多时,最初写完项目规划后,我就认认真真地去实现了它,后来拿着这个项目区参加了面试,同样面试官也拿这个项目来 ...
随机推荐
- 快速排序中BUG int 与 int *
#include <iostream>using namespace std;int QKPass(int* , int , int); //若声明为 int QKPass(int, i ...
- Linux下实时查看GPU状态
参考链接: http://blog.csdn.net/yao_yao_2015/article/details/53404389 1. 显示当前GPU使用情况 Nvidia自带了一个nvidia-sm ...
- kubadm创建k8s v1.10集群
kubadm创建k8s集群 1:服务器信息以及节点介绍 主机名 ip 备注 k8s-master 192.168.0.104 master etcd keepalived k8s-client1 19 ...
- redis 哨兵(sentinel)
redis哨兵 哨兵自动故障转移 自动通知应用最新master信息 无需担心,master挂了,程序不需要修改IP啥的,由哨兵自动完成 修改sentinel.conf protected-mode n ...
- node.js 关于 async的使用
第一次使用,感觉有点糊涂,后来实验明白了. 在串行执行中,经常会只做了第一步.后来明白了.是没有把回调函数放在里面简单就是: async.series( { ...
- 拍照一分钟,修图两小时,PS大神是这样修片的!
乌克兰有一个叫Viktoria Solidarnyh的美图艺术家,这个艺术家有一个特别的技能——P图,她P的图,水平真的非常赞...来感受一下.... 瞬间变成魔幻田园风... 编辑:千锋UI设计 ...
- TI and RI
https://blog.csdn.net/qq_27977257/article/details/70677661 51单片机的串口,是个全双工的串口,发送数据的同时,还可以接收数据.当串行发送完毕 ...
- Spring IOC(三)单例 bean 的注册管理
Spring IOC(三)单例 bean 的注册管理 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 在 Spring 中 ...
- Python 反射机制
Python的反射机制 Python的反射机制,就是反射就是通过字符串的形式,导入模块:通过字符串的形式,去模块寻找指定函数,并执行.利用字符串的形式去对象(模块)中操作(查找/获取/删除/添加)成员 ...
- Https如何确保传输安全的
1.对称加密算法 加密和解密算法是公开的,那个密钥是保密的, 只有双方才知道, 这样生成的加密消息(密文) 别人就无法得知了. 2.非对称加密算法 RSA算法非常有意思,是有一对儿钥匙, 一个是保密的 ...