|
发信人: alphatan ([`a:lfa:ta2n]), 信区: LinuxApp
标 题: 删除到“垃圾筒”的del脚本
发信站: BBS 水木清华站 (Thu Oct 16 00:43:31 2003), 转信
把脚本保存为del(无后缀名),然后扔到/usr/local/bin就可以了。
这里设的垃圾筒大小限制为500M,想大一点的就把里面的501改为1025吧。
如果超过上限就会询问用户是否清除(本来想给个选项为默认清除,
但想着要用到这个脚本的都是些不用想就删东西的人,所以没加这个选项了)
记得定时清垃圾筒哦。
- #!/bin/bash
- if [ ! -e ${HOME}/.Trash ]; then
- mkdir ${HOME}/.Trash
- fi
- trashVolumn=$(du -sm ${HOME}/.Trash |awk '{print $1}')
- sourceFiles=$@
- if [ $trashVolumn -ge 501 ]; then
- read -p "ERROR!!! Your Trash is out of 500M!! Clean ALL?(yes, or else)" cleanResponse
- cleanResponse=$(echo $cleanResponse |tr [A-Z] [a-z])
- if [ "$cleanResponse" = 'yes' ] ; then
- if cleanTrash ; then
- mv --target-directory=${HOME}/.Trash $sourceFiles
- fi
- else
- echo -e "I had NOT done ANY cleaning, Your Trash is still FULL!!" >&2
- fi
- else
- mv --target-directory=${HOME}/.Trash $sourceFiles
- fi
- function cleanTrash()
- {
- if rm -rf ${HOME}/.Trash/* ; then
- return 0
- else
- echo -e "CLeaning course FAILED!\n" >&2
- return 1
- fi
- }
复制代码
--
Learning is to improve, but not to prove.
※ 来源:·BBS 水木清华站 smth.org·[FROM: 218.19.43.161] |
|