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

相关推荐
马立杰1 小时前
H3CNE-33-BGP
运维·网络·h3cne
云空2 小时前
《DeepSeek 网页/API 性能异常(DeepSeek Web/API Degraded Performance):网络安全日志》
运维·人工智能·web安全·网络安全·开源·网络攻击模型·安全威胁分析
深度Linux2 小时前
Linux网络编程中的零拷贝:提升性能的秘密武器
linux·linux内核·零拷贝技术
没有名字的小羊3 小时前
Cyber Security 101-Build Your Cyber Security Career-Security Principles(安全原则)
运维·网络·安全
m0_465215793 小时前
TCP & UDP Service Model
服务器·网络·tcp/ip
千夜啊3 小时前
Nginx 运维开发高频面试题详解
运维·nginx·运维开发
存储服务专家StorageExpert4 小时前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
chian-ocean6 小时前
从理论到实践:Linux 进程替换与 exec 系列函数
linux·运维·服务器
拎得清n6 小时前
UDP编程
linux
敖行客 Allthinker6 小时前
从 UTC 日期时间字符串获取 Unix 时间戳:C 和 C++ 中的挑战与解决方案
linux·运维·服务器·c++