alias rm to mv

好多次在linux系统中rm -rf 系统文件,补救起来很困难,现在换了这个脚本还算安全多了,将rm命令换位mv至/delete/files文件夹内,嗯总算可以安全的rm -rf了。

💬  [🔸 369🔸 root@k8s1 ~]# 👉  cat /delete/delete.sh
#!/bin/bash
#note:rm well be careful

#set the delete files dir
DELDIR=/delete/files
DELSTRING[0]=$1
NOTDELDIRS=("/usr/bin" "/usr/sbin" "/" "/usr")
STAYTIME=10

RED(){
    echo -e "\033[31m\033[01m[ $1 ]\033[0m \n"
}

#checkout deletedir exist
[ ! -d $DELDIR ]&&mkdir -p $DELDIR

#checkout the files will be delete exists
[ -z "${DELSTRING[0]}" ]&&RED ""${DELSTRING[0]}" is null"&&exit

#checkout $1 -rf
[ "${DELSTRING[0]}" == "-rf" ]&&DELSTRING[0]=$2

#checkout the files is true or false
ls ${DELSTRING[0]} > /dev/null 2>&1
[ `echo $?` != "0" ]&&RED ""${DELSTRING[0]}" is not exist"&&exit

#checkout the files will be delete dir
for i in "${NOTDELDIRS[@]}"
do
    [ "${DELSTRING[0]}" == $i ]&&RED "hi,don't sheep ,you can't delete $i"&&exit
done

#mv this files to /delete/files
rmfile(){
mv ${DELSTRING[0]} $DELDIR
[ `echo $?` != "0" ]&&mv ${DELSTRING[0]} ${DELSTRING[0]}.bak&&mv ${DELSTRING[0]}.bak $DELDIR
}
rmfile > /dev/null 2>&1

#/delete/files auto clear
find $DELDIR -ctime $STAYTIME -type f -exec rm -rf {} \;
# mkdir /delete
# echo "alias rm=/delete/delete.sh" >> /etc/profile
# source /etc/profile