在CentOS系統中,防止誤刪重要文件可以通過以下幾種方法來實現:
chmod 600 /path/to/important/file
setfacl -m u:username:rwx /path/to/important/file
rsync、tar等工具定期備份重要文件。rsync -avz /path/to/important /backup/location
Bacula、Amanda等專業的備份解決方案。ext4文件系統支持日志功能,可以在文件系統層面防止數據丟失。trash-cli:將刪除的文件移動到回收站,而不是直接刪除。yum install trash-cli
trash /path/to/important/file
safe-rm:一個安全的刪除工具,可以防止誤刪。yum install safe-rm
srm /path/to/important/file
#!/bin/bash
BACKUP_DIR="/backup/location"
IMPORTANT_FILES="/path/to/important/*"
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BACKUP_FILE="$BACKUP_DIR/backup_$TIMESTAMP.tar.gz"
tar -czvf $BACKUP_FILE $IMPORTANT_FILES
setenforce 1
auditd記錄文件系統的操作,便于追蹤和恢復誤刪操作。yum install audit
systemctl enable auditd
systemctl start auditd
通過以上方法,可以大大減少在CentOS系統中誤刪重要文件的風險。根據具體需求和環境,選擇合適的方法進行實施。