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

相关推荐
Predestination王瀞潞7 分钟前
Cuda的安装
linux·人工智能·深度学习
石像鬼₧魂石36 分钟前
如何使用Kali Linux自带字典进行密码破解?
linux·运维·服务器
q***656936 分钟前
Nginx反向代理出现502 Bad Gateway问题的解决方案
运维·nginx·gateway
JiMoKuangXiangQu1 小时前
Linux 时间子系统 (1):基础框架概述
linux·timer·时间子系统·timekeeping
天选之女wow1 小时前
【Hard——Day8】65.有效数字、68.文本左右对齐、76.最小覆盖子串
linux·运维·redis·算法·leetcode
精英的英1 小时前
【嵌入式Linux开发】如何在Windows上开发Linux ARM版本QT程序
linux·arm开发·windows
咯哦哦哦哦1 小时前
linux patchelf工具 用法
linux·vscode·编辑器·gcc
努力的小帅1 小时前
Linux_进程控制(Linux入门到精通)
linux·网络·shell·进程创建·linux入门
睡觉然后上课1 小时前
如何让虚拟机运行速度翻倍
linux·arm开发·windows
喜欢你,还有大家1 小时前
DaemonSet && service && ingress的
linux·架构·kubernetes