Linux运维小细节之回收站(二)
作者:张岩峰,转载请注明出处 笔名:云烟旧梦
51CTO课程地址:https://edu.51cto.com/lecturer/12750547.html Linux技术交流群:1127825548
上一章我们讲过了回收站的构建,当然我们一步一步手动构建是很麻烦的,这里张老师在这里写了一个脚本,一键构建回收站功能:
一键搭建linux回收站功能:
[root@localhost ~]# cat Recycling_bin.sh
#!/bin/bash
#####################
# script name:zhang
# qq:1754815191
# creation time:2020-02-04
# update time:2020-02-04
# version:1.0
#####################
. /etc/init.d/functions
sleep 2
LANG=en
# Set up a recycling bin
mkdir -p ~/.trash &>/dev/null
if [ -d ~/.trash ]
then
cd ~/.trash
action "Establish ~/.trash" /bin/true
else
action "Establish ~/.trash" /bin/false
exit
fi
# Configuration the recycle bin master feature
echo "##### Recycle Stop Commaand Help #####"
cat >> ~/.bash_profile <<EOF
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
mv -i ~/.trash/\$@ ./
}
trash()
{
mv \$@ ~/.trash/
}
EOF
if [ $? = 0 ]
then
action "rm ----- remove" /bin/true
action "rl ----- View trash content" /bin/true
action "ur ----- Recovering specified files" /bin/true
else
action "rm ----- remove" /bin/false
action "rl ----- View trash content" /bin/false
action "ur ----- Recovering specified files" /bin/false
exit
fi
# Configuration the trash can-empty function
cat >> ~/.bashrc <<EOF
cleartrash()
{
read -p "clear sure?[n]" confirm
[ \$confirm == "y" ] || [ \$confirm == "Y" ] && /usr/bin/rm -rf ~/.trash/*
}
$..bashrc
EOF
if [ $? = 0 ]
then
action "cleartrash ----- Emptying the recycle bin" /bin/true
else
action "cleartrash ----- Emptying the recycle bin" /bin/false
exit
fi
sleep 2
[root@localhost ~]# . ~/.bash_profile
注意:还是需要手动重新加载一下配置文件
每一份赞赏源于懂得
赞赏
0人进行了赞赏支持
更多相关文章
- Oracle Linux 7.9+Oracle 12c+ASM安装文档--4、添加ASM磁盘组
- Oracle Linux 7.9+Oracle 12c+ASM安装文档--5、数据库软件安装
- 12c执行统计信息收集报ORA-12012 ORA-20001 ORA-06512
- dock 无法正常启动
- 顺序栈(C语言,静态栈)
- mysql数据查询关于字段为100000-130000-130400-130426的数据格式
- Elasticsearch 之 监控告警通知
- shell实现MySQL全量备份
- mysql查询指定字段以","拼接字符串作为结果返回