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后,重新登录终端即可使用

相关推荐
艾伦_耶格宇14 分钟前
【ACP】阿里云云计算高级运维工程师--ACP
运维·阿里云·云计算
一位摩羯座DBA1 小时前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组1 小时前
CentOS配置网络
linux·网络·centos
计算机毕设定制辅导-无忧学长1 小时前
西门子 PLC 与 Modbus 集成:S7-1500 RTU/TCP 配置指南(一)
服务器·数据库·tcp/ip
weixin_307779131 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
漫步企鹅2 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
cui_win2 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
梦在深巷、2 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
风清再凯2 小时前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible
深圳安锐科技有限公司2 小时前
深圳安锐科技发布国内首款4G 索力仪!让斜拉桥索力自动化监测更精准高效
运维·安全·自动化·自动化监测·人工监测·桥梁监测·索力监测