误用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

相关文章

Linux命令rm如何删除名字以“-”开头的文件

《Linux命令rm如何删除名字以“-”开头的文件》Linux中,命令的解析机制非常灵活,它会根据命令的开头字符来判断是否需要执行命令选项,对于文件操作命令(如rm、ls等),系统默认会将命令开头的某... 目录先搞懂:为啥“-”开头的文件删不掉?两种超简单的删除方法(小白也能学会)方法1:用“--”分隔命

Python函数的基本用法、返回值特性、全局变量修改及异常处理技巧

《Python函数的基本用法、返回值特性、全局变量修改及异常处理技巧》本文将通过实际代码示例,深入讲解Python函数的基本用法、返回值特性、全局变量修改以及异常处理技巧,感兴趣的朋友跟随小编一起看看... 目录一、python函数定义与调用1.1 基本函数定义1.2 函数调用二、函数返回值详解2.1 有返

Nginx屏蔽服务器名称与版本信息方式(源码级修改)

《Nginx屏蔽服务器名称与版本信息方式(源码级修改)》本文详解如何通过源码修改Nginx1.25.4,移除Server响应头中的服务类型和版本信息,以增强安全性,需重新配置、编译、安装,升级时需重复... 目录一、背景与目的二、适用版本三、操作步骤修改源码文件四、后续操作提示五、注意事项六、总结一、背景与

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

Java实现远程执行Shell指令

《Java实现远程执行Shell指令》文章介绍使用JSch在SpringBoot项目中实现远程Shell操作,涵盖环境配置、依赖引入及工具类编写,详解分号和双与号执行多指令的区别... 目录软硬件环境说明编写执行Shell指令的工具类总结jsch(Java Secure Channel)是SSH2的一个纯J

修复已被利用的高危漏洞! macOS Sequoia 15.6.1发布

《修复已被利用的高危漏洞!macOSSequoia15.6.1发布》苹果公司于今日发布了macOSSequoia15.6.1更新,这是去年9月推出的macOSSequoia操作... MACOS Sequoia 15.6.1 正式发布!此次更新修复了一个已被黑客利用的严重安全漏洞,并解决了部分中文用户反馈的

电脑提示d3dx11_43.dll缺失怎么办? DLL文件丢失的多种修复教程

《电脑提示d3dx11_43.dll缺失怎么办?DLL文件丢失的多种修复教程》在使用电脑玩游戏或运行某些图形处理软件时,有时会遇到系统提示“d3dx11_43.dll缺失”的错误,下面我们就来分享超... 在计算机使用过程中,我们可能会遇到一些错误提示,其中之一就是缺失某个dll文件。其中,d3dx11_4

游戏闪退弹窗提示找不到storm.dll文件怎么办? Stormdll文件损坏修复技巧

《游戏闪退弹窗提示找不到storm.dll文件怎么办?Stormdll文件损坏修复技巧》DLL文件丢失或损坏会导致软件无法正常运行,例如我们在电脑上运行软件或游戏时会得到以下提示:storm.dll... 很多玩家在打开游戏时,突然弹出“找不到storm.dll文件”的提示框,随后游戏直接闪退,这通常是由于

qt5cored.dll报错怎么解决? 电脑qt5cored.dll文件丢失修复技巧

《qt5cored.dll报错怎么解决?电脑qt5cored.dll文件丢失修复技巧》在进行软件安装或运行程序时,有时会遇到由于找不到qt5core.dll,无法继续执行代码,这个问题可能是由于该文... 遇到qt5cored.dll文件错误时,可能会导致基于 Qt 开发的应用程序无法正常运行或启动。这种错

电脑提示xlstat4.dll丢失怎么修复? xlstat4.dll文件丢失处理办法

《电脑提示xlstat4.dll丢失怎么修复?xlstat4.dll文件丢失处理办法》长时间使用电脑,大家多少都会遇到类似dll文件丢失的情况,不过,解决这一问题其实并不复杂,下面我们就来看看xls... 在Windows操作系统中,xlstat4.dll是一个重要的动态链接库文件,通常用于支持各种应用程序