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

相关推荐
神仙别闹4 分钟前
基于C语言 HTTP 服务器客户端的实验
服务器·c语言·http
Archy_Wang_111 分钟前
基于BaGet 构建NuGet私有库并实现类库打包到NuGet私有库
运维·jenkins
小狗爱吃黄桃罐头14 分钟前
正点原子【第四期】Linux之驱动开发学习笔记-10.1 Linux 内核定时器实验
linux·驱动开发·学习
初听于你15 分钟前
运维高级故障排除与恢复-SysRq
运维·服务器·安全
RPA机器人就用八爪鱼1 小时前
RPA自动化程序:企业数字化转型的智能引擎
运维·自动化·rpa
Kang强1 小时前
tcpdump 抓到 icmp 包,但是抓不到 tcp 包??
linux
demodashi6661 小时前
Linux下ag搜索命令详解
linux·运维·windows
無识1 小时前
Linux-第四章web服务
linux·运维·服务器
一叶知秋yyds2 小时前
Centos 安装 Docker教程
linux·docker·centos
fie88892 小时前
在CentOS 7上集成cJSON库的方法
linux·运维·centos