在Linux系統中,通常沒有一個像Windows那樣的明顯“回收站”功能。Linux通過其文件管理器(如Dolphin或Nautilus)提供了一個類似的回收站功能,用于臨時存儲被刪除的文件,以便用戶在必要時恢復它們。以下是詳細步驟:
cd ~/.local/share/Trash/files
cd ~/.Trash-1000
mkdir -p ~/trash_backup
cp -r ./* ~/trash_backup/
#!/bin/bash
# 定義回收站目錄和備份目錄
TRASH_DIR="$HOME/.local/share/Trash/files"
BACKUP_DIR="$HOME/TrashBackup"
# 創建備份目錄(如果尚未創建)
mkdir -p "$BACKUP_DIR"
# 復制回收站文件到備份目錄
cp -r "$TRASH_DIR"/* "$BACKUP_DIR"
# 輸出備份完成信息
echo "回收站文件已備份到 $BACKUP_DIR"
將上述腳本保存為 backup_trash.sh
,然后賦予執行權限并運行:
chmod +x backup_trash.sh
./backup_trash.sh
cron
來定期運行備份腳本。
編輯 crontab
文件:crontab -e
添加一行來設置備份頻率,例如每天凌晨2點備份:
0 2 * * * /path/to/backup_trash.sh
保存并退出編輯器。
find
命令:open terminal.
input sudo find / -name "文件名" to find the file you want to recover.
mv
命令將其移動回原位置。例如:mv /path/to/found/file /path/to/original/location.
debugfs
命令恢復Ext2/Ext3文件系統上的文件:first, you need to unmount the partition containing the deleted file. For example, if the file is in /boot directory, you can use the umount command: umount /boot.
Then, run the debugfs command and specify the partition to check. For example: debugfs /dev/sda1.
Use the lsdel command to list the deleted files.
If the file can still be recovered, you can use the dump command to copy the file content back to the original location.
請注意,如果文件所在的磁盤分區被重新掛載或者數據被新數據覆蓋,恢復文件的可能性就會降低。此外,如果使用的是ext3或ext4文件系統,由于它們在執行刪除操作時會清除指向被刪除文件的信息節點指針,因此恢復文件的可能性也相對較低。在這種情況下,使用數據恢復軟件可能是一個更好的選擇。