本文主要是介绍误用rm -rf *文件修复及修改rm指令为mv,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
昨晚迷迷糊糊,进错目录敲下rm -rf *命令删除文件,结果把一些重要文件都删了,这里记录下文件修复的经过(虽然最后没有弄好,感觉很大部分原因是当时没有权限,时间过的久了,文件被覆盖了),以及把rm 命令修改为mv命令,移动到指定目录下。
1.rm -rf 文件修复
发现自己误删后,第一步就是立即卸载分区或者设置为只读。这里,如果刚好你目前所在的分区是系统分区,那么就不能卸载了。
命令:
umount /dec/sda1 或者
mount -o remount,ro /dev/sda1
#这里的sda1就是你自己文件的分区,可以用指令查看
df -h #查看分区
删除文件,就是将文件的inode删除了,真正的文件还存在磁盘中,当然存数据被操作系统重新分配后也可能就找不回了。
我的文件系统时etx4,在网上找资料可以使用extundelete工具包。
该工具包可以修复ext3,ext4,还有个ext3grep只能修复ext3文件系统。软件地址 http://extundelete.sourceforge.net/
按照软件官方的说明,下载解压,直接进入文件夹
./configure
make
make install
执行上面的命令都需要root权限。
然后
extundelete --help
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 ./RECOVERED_FILESwith their inode number as extension (ie, file.12345).--restore-file 'path' Will restore file 'path'. 'path' is relative to rootof the partition and does not start with a '/'The restored file is created in the currentdirectory 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 optionto --restore-file, and there should be one per line.--restore-directory 'path'Will restore directory 'path'. 'path' is relative to theroot directory of the file system. The restoreddirectory is created in the output directory as 'path'.--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 openingthe file system.-B blocksize Uses blocksize as the block size when opening the filesystem. The number should be the number of bytes.--log 0 Make the program silent.--log filename Logs all messages to filename.
--log D1=0,D2=filename Custom control of log messages with comma-separatedExamples below: list of options. Dn must be one of info, warn, or--log info,error error. Omission of the '=name' results in messages--log warn=0 with the specified level to be logged to the console.--log error=filename If the parameter is '=0', logging for the specifiedlevel will be turned off. If the parameter is'=filename', messages with that level will be writtento filename.-o directory Save the recovered files to the named directory.The restored files are created in a directorynamed 'RECOVERED_FILES/' by default.
按照说明执行步骤,可以先
extundelete --inode 2 /dev/sda1
找到根节点,然后根据出来的提示一步步去找,知道找到自己删除的目录文件,再使用
extundelete --restore-inode 18090 /dev/sda1
#中间的18090就是你要回复的节点,当然还有其他的修复办法,参考--help
执行上面的步骤,就会在根目录下出现一个RESTORED_FILES文件夹,就可以去里面找自己的文件了。
2.修改rm指令
经过上面惨痛的教训,决定修改rm指令,步骤如下:
首先造自己的目录下简历一个delete文件夹,用来当回收站
mkdir delete
现在来修改bashrc
vim ./bashrc
添加命令如下:
#修改rm命令
alias rm=delete #命令别名,通过delete来实现rm改为mv
alias r=delete
alias rl='ls /home/temp/delete' #rl 命令显示回收站中的文件
alias ur=undelfile #ur 命令找回回收站的文件
undelfile()
{mv -i /home/temp/delete/\$@ ./
}
delete()
{mv $@ /home/temp/delete
}
修改完后
source .bashrc
现在自己就可以测试了,建立一个temp.txt然后自己 用rm temp.txt你就可以在delete目录下找到了。
原文链接:http://blog.csdn.net/u011956147/article/details/67634136
这篇关于误用rm -rf *文件修复及修改rm指令为mv的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!