一时大意,本来在.bashrc里封装了个命令gc=’git ch .;git clean -fd’,一进库,执行了下gc,然后把之前写了一周的代码删除个干干净净,找了很多办法还原,发现extundelete有作用。在这里作个笔记,下次误操作的时候用到再查(同样适用于rm 误删除的文件)。
1、将硬盘挂载为只读模式
sudo mount -o remount,ro /dev/sda5
2.安装extundelete
sudo apt-get install extundelete
3.查看当前被删除文件所在系统分区
df .
4.在被删除的目录下执行命令,获取Node号
ls -id .
5.查找被删除的文件
extundelete 所在分区 –inode Node号
sudo extundelete /dev/sda6 --inode 51119565
6.恢复文件
sudo extundelete 所在分区 –restore-file 文件路径
sudo extundelete /dev/sda6 --restore-file activity_main.xml___jb_old___
7、再将硬盘挂载为读写模式
sudo mount -o remount,rw /dev/sda6
附extundelete所有功能:
Usage: extundelete [options] [--] device-file
Options:
--version, -[vV] Print version and exit successfully.
--help, Print this help and exit successfully.
--superblock Print contents of superblock in addition to the rest.
If no action is specified then this option is implied.
--journal Show content of journal.
--after dtime Only process entries deleted on or after 'dtime'.
--before dtime Only process entries deleted before 'dtime'.
Actions:
--inode ino Show info on inode 'ino'.
--block blk Show info on block 'blk'.
--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RESTORED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path' Will restore file 'path'. 'path' is relative to root
of the partition and does not start with a '/' (it
must be one of the paths returned by --dump-names).
The restored file is created in the current
directory as 'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
--output-dir 'path' Restore files in the output dir 'path'.
By default the restored files are created under current directory 'RECOVERED_FILES'.
--restore-all Attempts to restore everything.
-j journal Reads an external journal from the named file.
-b blocknumber Uses the backup superblock at blocknumber when opening
the file system.
-B blocksize Uses blocksize as the block size when opening the file
system. The number should be the number of bytes.
end