您的位置:首页 > 运维架构 > Linux

rm -rf 命令带来的恶梦 修改rm命令;让rm 命令删除的文件到回收站

2014-12-14 21:39 381 查看
今天,哎,悲剧的一天。。。。。上午在linux下删除火狐浏览器的时候,用错了命令我想把/usr/目录下面的带mozilla的文件都删除掉,结果用这个命令rm -rf mozilla *意思就是执行了rm -rf mozilla 然后又执行了rm -rf * 所以我的/usr/啥都没了,所以回到解放前了,我查了一下网上关于通过rm -rf误删除的文件进行恢复的方法,发现我现在因为/usr目录下面的文件全部删除。所以全不能恢复的可能性不大了,只好重装系统.并且等我吃饭回来的时候连系统文件也进不去了,只好通过ext2explore
软件,在windows下把Linux系统中的主文件里面的东西都copy到windows的桌面上。

简单说一下重装系统的艰苦过程:

1 听一哥们说,装ubuntu14.04的,然后通过在计算机-管理-然后再磁盘管理里面,选择到F盘右键,然后压缩,我弄出了大概40GB的空间给了LINUX.。弄完后就用那个u盘开始装。发现装完之后,这个版本的输入法非常的垃圾,不适用,就开始自己各种折腾。大概折腾了有3、4个小时还是没有把输入法折腾好。我估计是在我安装的时候没有联网的原因,最好可以联网。

2 怎么办呢,继续装呗。然后自己在网上找了个下ubuntu 12.04 32位版本

mirrors.163.com/ubuntu-releases/precise/ubuntu-12.04.5-desktop-i386.iso
安装完后,然后用ultaral iso软件把iso刻录到U盘里面,然后又重新装,电脑启动的时候 狂按del键,然后再按F12,然后选择USB,直接覆盖安装就OK了。这个版本就可以啊,。输入法是正常的。

再说一下,修改rm命令,让rm删除http://0x55aa.sinaapp.com/linux/1156.htmlhttp://www.cnblogs.com/jtf-china/archive/2011/05/27/2059872.html

1  Install trash-cli

 
2. Set up the script

In Ubuntu enter this in a terminal:
#!/bin/bash
# command name: trash-rm
shopt -s extglob
recursive=1
declare -a cmd
((i = 0))
for f in "$@"
do
case "$f" in
(-*([fiIv])r*([fiIv])|-*([fiIv])R*([fiIv]))
tmp="${f//[rR]/}"
if [ -n "$tmp" ]
then
#echo "\$tmp == $tmp"
cmd[$i]="$tmp"
((i++))
fi
recursive=0 ;;
(--recursive) recursive=0 ;;
(*)
if [ $recursive != 0   -a  -d "$f" ]
then
echo "skipping directory: $f"
continue
else
cmd[$i]="$f"
((i++))
fi ;;
esac
done
trash "${cmd[@]}"


注意:12.04以上的版本,把最后一行的trash换成trash-put。

执行权限

3. Create an alias for "rm" to use "trash-rm"

In Ubuntu, run this in a terminal:

and enter this at the end of the file:

and save it.

Then reload bashrc by running the following command in a terminal:

That's it! Now try it out by deleting files the way you always do, using "rm" and "rm -r".

Final trash-cli tips

Since you've installed the trash-cli utility, now you can use the following commands for manipulating the trash from the command line (the names are self explanatory):

Update: to get this to work for "sudo rm" as well, copy

wilo108's sudo wrapper in your ~/.bashrc file. Without it, this will not work when "rm" is used with "sudo"!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 命令