误用rm -rf *文件修复及修改rm指令为mv
2017-03-28 11:45
176 查看
昨晚迷迷糊糊,进错目录敲下rm -rf *命令删除文件,结果把一些重要文件都删了,这里记录下文件修复的经过(虽然最后没有弄好,感觉很大部分原因是当时没有权限,时间过的久了,文件被覆盖了),以及把rm 命令修改为mv命令,移动到指定目录下。
命令:
删除文件,就是将文件的inode删除了,真正的文件还存在磁盘中,当然存数据被操作系统重新分配后也可能就找不回了。
我的文件系统时etx4,在网上找资料可以使用extundelete工具包。
该工具包可以修复ext3,ext4,还有个ext3grep只能修复ext3文件系统。软件地址 http://extundelete.sourceforge.net/
按照软件官方的说明,下载解压,直接进入文件夹
执行上面的命令都需要root权限。
然后
按照说明执行步骤,可以先
找到根节点,然后根据出来的提示一步步去找,知道找到自己删除的目录文件,再使用
执行上面的步骤,就会在根目录下出现一个RESTORED_FILES文件夹,就可以去里面找自己的文件了。
首先造自己的目录下简历一个delete文件夹,用来当回收站
现在来修改bashrc
添加命令如下:
修改完后
现在自己就可以测试了,建立一个temp.txt然后自己 用rm temp.txt你就可以在delete目录下找到了。
原文链接:http://blog.csdn.net/u011956147/article/details/67634136
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_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 '/' 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. --restore-directory 'path' Will restore directory 'path'. 'path' is relative to the root directory of the file system. The restored directory 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 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. --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-separated Examples 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 specified level will be turned off. If the parameter is '=filename', messages with that level will be written to filename. -o directory Save the recovered files to the named directory. The restored files are created in a directory named '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命令;让rm 命令删除的文件到回收站
- 【Linux系统】修改Linux系统 rm指令,避免误删文件
- rm -rf 后的文件如何恢复?
- 还原rm –rf 删除的文件(ext2文件系统)
- linux恢复 rm -rf 删除的文件
- 一天一linux命令(9) cp rm mv文件和目录的管理
- Linux修改文件时候出现崩溃,产生了一个.swap交换文件,如何修复?
- 修复文件关联-EXE文件关联被修改后所有应用程序都打不开
- Linux目录与文件创建时间 / 修改时间 / 访问时间 / 指令 touch(鸟哥的Linux私房菜基础学习篇第三版-第七章)
- 正在写入的文件被mv或rm会怎样
- Delphi修改Access密码,压缩与修复,建立Access数据库文件
- Discuz X2.5 漏洞修复失败,发现您的目录及文件无修改权限
- linux错误修改inittab文件,无法启动,进入单用户模式进行修复的办法
- linux ext3 ext4文件系统下 恢复 rm -rf 误删除文件
- fstab文件修改错误后修复
- 使用extundelete恢复linux ext3 ext4文件系统下由 rm -rf 误删除文件
- 无须修改php.ini等配置文件,修复session_start错误的方式
- 清空文件和清空文件夹的方法+cp,mv,rm
- Linux下rm -rf 后恢复文件
- Delphi修改Access密码,压缩与修复,建立Access数据库文件