Linux禁用危险命令和防止误操作

禁用rm命令

编辑/etc/profile文件,结尾添加

text 复制代码
######  rm prevent ######
alias rm='echo can not use rm command

使用source命令生效

bash 复制代码
source /etc/profile

效果

使用mv命令代替rm命令

将需要删除的文件移动到特定的目录,比如/home/sharedir/

在.bashrc目录设置alias

bash 复制代码
alias rmf='rm -i'

定时脚本

bash 复制代码
#!/bin/sh
####################################################
#######    Scheduled file deletion script    #######
####################################################
##                                                ##
####################################################
##   1. Executed every day at 1 am
##   2. Delete files in the /data/recycleDir/ directory
####################################################
location="/data/recycleDir/"
find $location -mtime +48 -type f |xargs rmf -f

使用crontab -e 定时启动del.sh脚本

text 复制代码
0 1 * * * /bin/sh /data/scripts/del.sh

防止误操作关机

text 复制代码
alias shutdown=''
alias init=''
alias reboot=''

需要使用这些命令时在profile文件中去掉,source后,重新登录终端即可使用

相关推荐
江畔何人初2 小时前
iptables 和 IPVS 代理模式 Service 的区别
linux·运维·服务器·网络·云原生·kubernetes·代理模式
2601_949221034 小时前
Splashtop赋能企业级远程办公全场景安全连接成选型优选
运维·人工智能·安全
七度黑光4 小时前
用 openclaw 给故障复盘打分:质量审核自动化实践
运维·服务器·前端·数据库·自动化
xuefeiniao5 小时前
docker.desktop无法启动,导出镜像后
服务器·docker
123过去5 小时前
nfc-list使用教程
linux·网络·测试工具·安全
last demo6 小时前
mysql
运维·数据库·mysql·oracle
灰阳阳6 小时前
Dockerfile实践-构建Nginx镜像
运维·nginx·docker·dockerfile
evo-master6 小时前
网络故障排除方法
linux·服务器·网络
Johnstons7 小时前
网络流量监控工具怎么选
运维·网络·网络故障排除·网络流量分析·网络性能监控
爱学习的小囧8 小时前
VMware Horizon 8 智能卡认证信任库配置攻略:新增 Root CA 导入指南
服务器·esxi·vmware·horizon