Linux的rm 、reboot、shutdown、fdisk等命令误操作会造成严重后果,可以重写这些命令降低风险。一般是重写/etc/bashrc (非/root/.bashrc,这里的环境变量只有root用户才会加载),末尾添加重写代码,保存后 source /etc/bashrc加载或重新连接sshd
##### rewrite begin####
alias ct=cleantrash #清空垃圾箱
alias lt=lstrash #垃圾箱列表
alias rm=rm_plus #重写删除命令
alias reboot=reboot_plus #重写重启命令
alias shutdown=shutdown_plus #重启关机命令
rm_plus() {
for i in $@
do
if [ -d "${i}" ] || [ -f "${i}" ]
then
mv ${i} /home/.trash/
fi
done
echo '已删除至垃圾箱,查看:lt或listtrash,清空:ct或cleantrash'
}
lstrash() {
echo '垃圾箱列表'
ls /home/.trash
#cd /home/.trash && `du -sh *` && cd -
}
cleantrash() {
read -p "清空垃圾箱吗[y/n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /usr/bin/rm -rf /home/.trash/*
}
reboot_plus() {
read -p "确定重启吗[y/n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /usr/sbin/reboot
}
shutdown_plus() {
read -p "确定关机吗[y/n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /usr/sbin/shutdown
}
##### rewrite end #####
原文链接:https://blog.csdn.net/qq_39506978/article/details/104170261
网友评论