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
注意:还是需要手动重新加载一下配置文件
标签:运维小,bin,false,-----,Linux,action,trash,true,回收站 来源: https://blog.51cto.com/12760547/2666774