西北小农民 于 2021-07-05 10:42:30 发布
197
收藏
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1. 创建脚本rm.sh
#!/bin/bash
TRASH_DIR="$HOME/rm_bak"
if [ ! -d $TRASH_DIR ]; then
mkdir $TRASH_DIR
fi
for i in $*; do
if [[ "$i" == "-rf" ]];then
continue
elif [[ "$i" == "-r" ]];then
continue
elif [[ "$i" == "-f" ]];then
continue
fi
#echo "参数 $i"
STAMP=`date -d today +"%Y-%m-%d-%T"`
fileName=`basename -- $i`
first_char="${i:0:1}"
#echo $first_char
if [[ "$first_char" == "/" ]];then
echo "["$STAMP"] del from "$i >> $TRASH_DIR/rm.log
else
echo "["$STAMP"] del from "`pwd`"/"$i >> $TRASH_DIR/rm.log
fi
mv $i $TRASH_DIR/$fileName.$STAMP
done
2. 修改.bashrc
$ cd
$ vim .bashrc
添加
alias rm='bash /home/*****/rm.sh'
其中***为你放置rm.sh脚本的路径
$ source .bashrc
转自 https://blog.csdn.net/QQ1183678930/article/details/118484482