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

相关文章

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是一个重要的动态链接库文件,通常用于支持各种应用程序

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Python包管理工具核心指令uvx举例详细解析

《Python包管理工具核心指令uvx举例详细解析》:本文主要介绍Python包管理工具核心指令uvx的相关资料,uvx是uv工具链中用于临时运行Python命令行工具的高效执行器,依托Rust实... 目录一、uvx 的定位与核心功能二、uvx 的典型应用场景三、uvx 与传统工具对比四、uvx 的技术实

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

电脑蓝牙连不上怎么办? 5 招教你轻松修复Mac蓝牙连接问题的技巧

《电脑蓝牙连不上怎么办?5招教你轻松修复Mac蓝牙连接问题的技巧》蓝牙连接问题是一些Mac用户经常遇到的常见问题之一,在本文章中,我们将提供一些有用的提示和技巧,帮助您解决可能出现的蓝牙连接问... 蓝牙作为一种流行的无线技术,已经成为我们连接各种设备的重要工具。在 MAC 上,你可以根据自己的需求,轻松地

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

电脑提示Winmm.dll缺失怎么办? Winmm.dll文件丢失的多种修复技巧

《电脑提示Winmm.dll缺失怎么办?Winmm.dll文件丢失的多种修复技巧》有时电脑会出现无法启动程序,因为计算机中丢失winmm.dll的情况,其实,winmm.dll丢失是一个比较常见的问... 在大部分情况下出现我们运行或安装软件,游戏出现提示丢失某些DLL文件或OCX文件的原因可能是原始安装包

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失