0
点赞
收藏
分享

微信扫一扫

一个脚本来避免rn删除掉文件不可修复的悲剧


#!/bin/bash

echo <<END
This script create a new folder named .TrAsH in home directory
and aliased your command *<rm>* usinf function trash, then all your 
removed file weill be saved in ~/.TrAsH. You can choose to clear
it at fixed time or by yourself using the command *<rmf>* to clear them
END
if [ -d ~/.TrAsH ] 
then
	echo "There is a folder named .TrAsH. Please changed it to another name"
	exit 1
else
	mkdir ~/.TrAsH
fi
cp ~/.bashrc ~/.bashrc.bak
cat <<ENDF >>~/.bashrc
alias rm=trash
alias ur=undelfile
alias rmf='/bin/rm -rf ~/.TrAsH/*'
undelfile()
{
    mv -i ~/.TrAsH/$@ ./
}
trash()
{
    mv -i $@ ~/.TrAsH/
}
ENDF
source ~/.bashrc

 

另外, 在万一真的悲剧发生了, 还有一个办法能挽回一些损失。(这个方法来自Coolshell--酷壳 ,未验证,速度可能比较慢)


grep -a -B 50 -A 60 'some string in the file' /dev/sda1 > results.txt


说明:

  • 关于grep的-a意为–binary-files=text,也就是把二进制文件当作文本文件。
  • -B和-A的选项就是这段字符串之前几行和之后几行。
  • /dev/sda1,就是硬盘设备,
  • > results.txt,就是把结果重定向到results.txt文件中。
举报

相关推荐

0 条评论