代码拉取完成,页面将自动刷新
#!/bin/bash
## rt/remove_trash.sh
## 1. It is designed to replace old command rm without having to delete it.
## 2. It can avoid deleting files or directories with old command rm by mistake.
## 3. You can continue to use new 'rm' to delete files or directories, and it will move the target file or directory to
## a trash directory instead of directly deleting them.
## 4. Besides, you can set the time to automatically empty the trash directory.
## Author: WeigangZheng, zwg2016@yeah.net
## Date: 2020-04-05
##******First step******
## git clone https://github.com/Velcon-Zheng/rm-rt.git
## cp rm-rt/rt ~/ ##cp rm-rt/rt to your directory you want;
## echo 'alias "rm= ~/rt"' >> ~/.bashrc ; source ~/.bashrc;
##******Second step******
## crontab -e
## 0 0 * * 0 rm -rf ~/zwg.trash/*
#########################
#alias rm="~/rt" # Replace rm command with rt command, the "~/rt" should be set to your global path. It should be written in ~/.bashrc
Trashdir="~/zwg.trash" # Set to your trash dirctory, and suggest not set to your home ~/
## Check the order is correct
if [ ! -d $Trashdir ]; then
echo -e "Warning: $Trashdir not exist;\nTry to creat $Trashdir"
mkdir $Trashdir || exit ;
fi
if [ $# -lt 1 ]; then
echo "Error: no target for rm"
echo "Usage: rm myfile mydirectory"
exit
fi
AA="del"
BB=`basename $1`
CC=1
DD=1
onoff="No"
Time=`date | sed 's/ \+/-/g'`
## move the target files or directories to a trash directory or permanently delete them
for i in $*; do
if [ $CC -lt 2 ]
then
if [ "$AA" == "$BB" ]
then
DD=$[DD+1]
#read -t 10 -p "***请确认是否永久删除文件或文件夹(Are you sure to permanently delete files or directories? Y/N)***:" onoff
read -t 10 -p "Are you sure to permanently delete files or directories? Y/N:" onoff
echo -e "\n"
if [ "$onoff" == "Y" ] || ( echo $onoff | grep -qi "Yes" )
then
unalias rm
fi
else
TrashFileName=`basename $i`
mv $i $Trashdir/$TrashFileName-$Time
fi
else
if [ $DD -ge 2 ] && ( [ "$onoff" == "Y" ] || ( echo $onoff | grep -qi "Yes" ) )
then
rm -rif $i
else
TrashFileName=`basename $i`
mv $i $Trashdir/$TrashFileName-$Time
fi
fi
CC=$[CC+1]
done
if [ $DD -ge 2 ] && ( [ "$onoff" == "Y" ] || ( echo $onoff | grep -qi "Yes" ) )
then
alias rm="~/rt"
echo -e "Warning: have permanently deleted the target file or directory \n"
else
echo -e "Finished: have moved the target file or directory to $Trashdir \n"
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。