误用rm -rf *文件修复及修改rm指令为mv

2024-06-20 19:32
文章标签 指令 修改 修复 rm rf 误用 mv

本文主要是介绍误用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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1079050

相关文章

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

mss32.dll文件丢失怎么办? 电脑提示mss32.dll丢失的多种修复方法

《mss32.dll文件丢失怎么办?电脑提示mss32.dll丢失的多种修复方法》最近,很多电脑用户可能遇到了mss32.dll文件丢失的问题,导致一些应用程序无法正常启动,那么,如何修复这个问题呢... 在电脑常年累月的使用过程中,偶尔会遇到一些问题令人头疼。像是某个程序尝试运行时,系统突然弹出一个错误提

电脑提示找不到openal32.dll文件怎么办? openal32.dll丢失完美修复方法

《电脑提示找不到openal32.dll文件怎么办?openal32.dll丢失完美修复方法》openal32.dll是一种重要的系统文件,当它丢失时,会给我们的电脑带来很大的困扰,很多人都曾经遇到... 在使用电脑过程中,我们常常会遇到一些.dll文件丢失的问题,而openal32.dll的丢失是其中比较

电脑win32spl.dll文件丢失咋办? win32spl.dll丢失无法连接打印机修复技巧

《电脑win32spl.dll文件丢失咋办?win32spl.dll丢失无法连接打印机修复技巧》电脑突然提示win32spl.dll文件丢失,打印机死活连不上,今天就来给大家详细讲解一下这个问题的解... 不知道大家在使用电脑的时候是否遇到过关于win32spl.dll文件丢失的问题,win32spl.dl

Nginx指令add_header和proxy_set_header的区别及说明

《Nginx指令add_header和proxy_set_header的区别及说明》:本文主要介绍Nginx指令add_header和proxy_set_header的区别及说明,具有很好的参考价... 目录Nginx指令add_header和proxy_set_header区别如何理解反向代理?proxy

Linux修改pip和conda缓存路径的几种方法

《Linux修改pip和conda缓存路径的几种方法》在Python生态中,pip和conda是两种常见的软件包管理工具,它们在安装、更新和卸载软件包时都会使用缓存来提高效率,适当地修改它们的缓存路径... 目录一、pip 和 conda 的缓存机制1. pip 的缓存机制默认缓存路径2. conda 的缓

Linux修改pip临时目录方法的详解

《Linux修改pip临时目录方法的详解》在Linux系统中,pip在安装Python包时会使用临时目录(TMPDIR),但默认的临时目录可能会受到存储空间不足或权限问题的影响,所以本文将详细介绍如何... 目录引言一、为什么要修改 pip 的临时目录?1. 解决存储空间不足的问题2. 解决权限问题3. 提

Linux文件名修改方法大全

《Linux文件名修改方法大全》在Linux系统中,文件名修改是一个常见且重要的操作,文件名修改可以更好地管理文件和文件夹,使其更具可读性和有序性,本文将介绍三种在Linux系统下常用的文件名修改方法... 目录一、引言二、使用mv命令修改文件名三、使用rename命令修改文件名四、mv命令和rename命

电脑提示msvcp90.dll缺少怎么办? MSVCP90.dll文件丢失的修复方法

《电脑提示msvcp90.dll缺少怎么办?MSVCP90.dll文件丢失的修复方法》今天我想和大家分享的主题是关于在使用软件时遇到的一个问题——msvcp90.dll丢失,相信很多老师在使用电脑时... 在计算机使用过程中,可能会遇到 MSVCP90.dll 丢失的问题。MSVCP90.dll 是 Mic

mybatis-plus 实现查询表名动态修改的示例代码

《mybatis-plus实现查询表名动态修改的示例代码》通过MyBatis-Plus实现表名的动态替换,根据配置或入参选择不同的表,本文主要介绍了mybatis-plus实现查询表名动态修改的示... 目录实现数据库初始化依赖包配置读取类设置 myBATis-plus 插件测试通过 mybatis-plu