浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Linux避免用rm误删文件 - 遗失的记忆 - 博客大巴

Linux避免用rm误删文件

日期:2010-12-11 | 分类:Linux使用

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://freakrobot.blogbus.com/logs/88281920.html

因为大部分的的linux发型套件已经采用了ext3/4文件系统,又因为rm命令删除的文件是不进垃圾箱的,所以用rm误删的文件一般是不能恢复的。

Q: How can I recover (undelete) deleted files from my ext3 partition?

Actually, you can't! This is what one of the developers, Andreas Dilger, said about it:

In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas ext2 just marks these blocks as unused in the block bitmaps and marks the inode as "deleted" and leaves the block pointers alone.

因此我们要尽量避免文件被误删,我们创建一个新的命令del脚本来删除文件,将下面脚本存储在/usr/bin下,以后都用它来删除文件:

#!/bin/bash
mkdir~/.Trash &> /dev/null
while [ ! -z "$1" ]; do
    mv "$1" ~/.Trash/
    shift
done

 

posted on 2013-04-23 16:43  lexus  阅读(280)  评论(0编辑  收藏  举报