linux 垃圾回收站是哪,Linux的垃圾回收站

Linux下建立类似windows的回收站

玩Linux人都知道rm、rm -rf的厉害,为了不小心删除问题,我做了一些小改变,适合Linux下有windows那样的回收站,一旦删除还可以找回被误删除的文件。如下操作。

我所在的操作系统的环境root@ubuntu:~/test# cat /etc/issue

Ubuntu 14.04.2 LTS \n \l

root@ubuntu:~/test# uname -a

Linux ubuntu 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

快速执行mkdir -p ~/.Trash

cat >>~/.bashrc<

#add by caimengzhi at $(date +%F) for Linux trash start

alias rm=trash

alias rl='ls ~/.Trash'

alias ur=undelfile

undelfile()

{

mv -i ~/.Trash/\$@ ./

}

trash()

{

mv \$@ ~/.Trash/

}

cleartrash()

{

read -p "Clear trash?[n]" confirm

[ \$confirm == 'y' ] || [ \$confirm == 'Y' ]  && /usr/bin/rm -rf ~/.Trash/*

}

#add by caimengzhi at $(date +%F) for Linux trash end

EOF

source ~/.bashrc

说明:

1. ~/.Trash就是以后被删除的文件和文件夹移动到的地方,也就是回收站

2. \$confirm 是实现脱意思,也就是最后在文件中就是$confirm。其中\$@一样

3. 上面的作用,说白了就是命令rm 的重命名。

使用语法:

rm(删除),ur(撤销),rl(列出回收站),cleartrash(清空回收站)命令了。

#删除一个文件夹和文件都会被移动到回收站中。

$rm  filedirctory

#删除一个文件

$rm  file.txt

#撤销对file.txt的删除

$ur  file.txt

#撤销filedirctory文件夹

$ur  filedirctory

#列出回收站

$rl

#清空回收站

cleartrash

-------------------------------------------------------------------------------------------

具体操作过程如下:root@ubuntu:~/test# echo "1">1.txt

root@ubuntu:~/test# echo "2">2.txt

root@ubuntu:~/test# mkdir 123

root@ubuntu:~/test# ll

total 20

drwxr-xr-x 3 root root 4096 Jan 16 14:07 ./

drwx------ 6 root root 4096 Jan 16 14:05 ../

drwxr-xr-x 2 root root 4096 Jan 16 14:07 123/

-rw-r--r-- 1 root root    2 Jan 16 14:07 1.txt

-rw-r--r-- 1 root root    2 Jan 16 14:07 2.txt

root@ubuntu:~/test# mkdir -p ~/.Trash

root@ubuntu:~/test# ls ~/.Trash/

删除文件root@ubuntu:~/test# ll

total 20

drwxr-xr-x 3 root root 4096 Jan 16 14:07 ./

drwx------ 6 root root 4096 Jan 16 14:05 ../

drwxr-xr-x 2 root root 4096 Jan 16 14:07 123/

-rw-r--r-- 1 root root    2 Jan 16 14:07 1.txt

-rw-r--r-- 1 root root    2 Jan 16 14:07 2.txt

root@ubuntu:~/test# rm 1.txt    #删除文件

root@ubuntu:~/test# ll

total 16

drwxr-xr-x 3 root root 4096 Jan 16 14:09 ./

drwx------ 6 root root 4096 Jan 16 14:05 ../

drwxr-xr-x 2 root root 4096 Jan 16 14:07 123/

-rw-r--r-- 1 root root    2 Jan 16 14:07 2.txt

2. 撤销删除文件root@ubuntu:~/test# rl

1.txt

root@ubuntu:~/test# ls ~/.Trash/

1.txt

root@ubuntu:~/test# ur 1.txt

root@ubuntu:~/test# ls ~/.Trash/

root@ubuntu:~/test# ls

123  1.txt  2.txt

root@ubuntu:~/test# cat 1.txt

1

3. 删除文件夹root@ubuntu:~/test#

root@ubuntu:~/test# ls

123  1.txt  2.txt

root@ubuntu:~/test# rm 123        #删除文件

root@ubuntu:~/test# rl

123

root@ubuntu:~/test# ls ~/.Trash/  #删除的文件夹已经跑到回收站中了

123

root@ubuntu:~/test# ls

1.txt  2.txt

4. 撤销删除文件夹root@ubuntu:~/test# rl

123

root@ubuntu:~/test# ls ~/.Trash/

123

root@ubuntu:~/test# ur 123

root@ubuntu:~/test# rl

root@ubuntu:~/test# ls

123  1.txt  2.txt

5. 清空回收站root@ubuntu:~/test# ls

123  1.txt  2.txt

root@ubuntu:~/test# rm *

root@ubuntu:~/test# ls

root@ubuntu:~/test# rl

123  1.txt  2.txt

root@ubuntu:~/test# cleartrash

Clear trash?[n]y

root@ubuntu:~/test# ls

root@ubuntu:~/test# rl

6. 此时若是恢复的时候没有加指定的参数问题

此时就会吧垃圾回收站移动到当前文件夹内,且更名为.Trashroot@ubuntu:~/test# ur

root@ubuntu:~/test# ls

root@ubuntu:~/test# rl

ls: cannot access /root/.Trash: No such file or directory

root@ubuntu:~/test# ll

total 12

drwxr-xr-x 3 root root 4096 Jan 16 14:29 ./

drwx------ 5 root root 4096 Jan 16 14:29 ../

drwxr-xr-x 3 root root 4096 Jan 16 14:29 .Trash/

root@ubuntu:~/test# cd .Trash/

root@ubuntu:~/test/.Trash# ls

1.txt  2.txt  3.txt

root@ubuntu:~/test/.Trash# cd ..

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值