在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文件系统,由于它们在执行删除操作时会清除指向被删除文件的信息节点指针,因此恢复文件的可能性也相对较低。在这种情况下,使用数据恢复软件可能是一个更好的选择。