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