Linux如何恢复删除的文件?
以前一小心,创建了一个~
的目录,于是想都没想的,就直接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
7 回答5.3k 阅读
4 回答4k 阅读
2 回答5.9k 阅读✓ 已解决
2 回答2.5k 阅读✓ 已解决
1 回答2.3k 阅读✓ 已解决
2 回答800 阅读✓ 已解决
2 回答3.2k 阅读
如果你是用rm删除的。。。那么很难。具体怎么实现?据说无法实现。。。
记得《unix痛恨者手册》中说:在unix中你一不小心rm掉珍贵的文件之后你才能学会深思熟慮,才能学会备份,才能成长成出色的系统管理员。。。
如果你是在图形界面中圈起来点del的,那么你可以在回收站里面找到你误删的文件。图形界面下的回收站会在文件夹的导航栏里面找到。