Linux如何恢复删除的文件?

新手上路,请多包涵

Linux如何恢复删除的文件?

阅读 5.1k
5 个回答

如果你是用rm删除的。。。那么很难。具体怎么实现?据说无法实现。。。
记得《unix痛恨者手册》中说:在unix中你一不小心rm掉珍贵的文件之后你才能学会深思熟慮,才能学会备份,才能成长成出色的系统管理员。。。

如果你是在图形界面中圈起来点del的,那么你可以在回收站里面找到你误删的文件。图形界面下的回收站会在文件夹的导航栏里面找到。

最糟糕的命令

rm -rf /
chmod -R 777 /

都执行过,之后就想剁手。

以前一小心,创建了一个~的目录,于是想都没想的,就直接rm -r ~,潇洒回车后,立马觉得不对,于是c-c,头皮一阵发麻,然后ls -a之后,发现掉了大把的.*文件,然后找工具,我用OSX,貌似发现一两个,但都需要收费,一下想了,就再自己配置吧,重要的是.emacs,.emacs.d都没了,于是我也懒得配置了,改用了Vim。

既然删除了,就重来吧。

alias rm='underscript', 这样你就能在Trash中找到你误删的文件了。

#!/bin/sh
pause_print_error(){
  read -n1 -p "Press any key to continue..."
  exit $1
}

for p in "$@"; do
if ([ "$OSTYPE" = "cygwin" ] && [ "${p##*:}" != "$p" ]); then
    path=`echo $p | sed -e 's/D:/d:/g' -e 's/"//g' -e 's/\\\\/\\//g' -e 's/://g' -e 's/^/\/cygdrive\//g'`
else
    path=$p
fi

touch "$path"

error=$?
if [ $error != 0 ]; then
    pause_print_error $error
fi

rootpath=`df "$path" | awk 'FNR == 2 {print $6}'`

error=$?

if [ $error != 0 ]; then
    pause_print_error $error
fi

if ([ "$rootpath" = "/" ] || [ "$rootpath" = "/home" ])
then
  rootpath=~
fi

if [ ! -d $rootpath/Trash/ ]
then
    mkdir $rootpath/Trash/
fi

error=$?
if [ $error != 0 ]; then
    pause_print_error $error
fi

newpath=`basename "$path"`
while [ -e $rootpath/Trash/"$newpath" ]
do
    newpath="1${newpath}"
done

mv -i "$path" $rootpath/Trash/"${newpath}"

error=$?
if [ $error != 0 ]; then
    pause_print_error $error
fi

done

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题