Author: Zhang Yanfeng, please indicate the source pseudonym: clouds dreams
51CTO course address: https://edu.51cto.com/lecturer/12750547.html Linux technology exchange group: 1127825548
In the last chapter, we talked about the construction of the recycle bin. Of course, it is very troublesome for us to build it step by step manually. Here, Mr. Zhang wrote a script here to build the recycle bin function with one click:
One-click build linux recycle bin function:
[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
be
# 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
be
# 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
be
sleep 2
[root@localhost ~]# . ~/.bash_profile
Note: You still need to manually reload the configuration file