Linux 系统中 Notepad 本身无内置备份功能,可通过命令行工具或图形工具实现文件备份与恢复,以下是常用方法:
cp 命令:复制文件或目录到指定位置
# 备份单个文件
cp /path/to/file.txt /backup/file.txt.bak
# 备份整个目录(递归复制)
cp -r /path/to/directory /backup/directory.bak
tar 命令:打包并压缩文件/目录
# 备份目录为压缩包
tar -czvf backup.tar.gz /path/to/directory
# 解压恢复
tar -xzvf backup.tar.gz -C /restore/path
rsync 命令:同步文件(支持增量备份)
# 本地备份
rsync -avz /source/path /backup/path
# 远程备份(需配置SSH)
rsync -avz /source/path user@remote:/backup/path
cp 或 tar 备份,直接复制文件回原路径即可:cp /backup/file.txt.bak /path/to/file.txt
tar -xzvf backup.tar.gz -C /path/to/restore
extundelete(仅限 ext3/ext4 文件系统):
sudo apt-get install extundelete # 安装
sudo extundelete /dev/sda1 --restore-file /path/to/deleted/file # 恢复单个文件
sudo extundelete /dev/sda1 --restore-directory /path/to/deleted/dir # 恢复目录
testdisk/photorec:
testdisk:支持多种文件系统,可恢复分区或文件。photorec:专注于恢复图片、文档等文件类型。若使用 Git 等版本控制系统,可通过提交历史回退文件:
git checkout <commit-hash> -- /path/to/file # 恢复到指定版本
根据需求选择合适工具,简单场景可用 cp/tar,复杂场景(如系统级恢复)可尝试 extundelete 或 testdisk。