linux回收站

回收站(trash),为了可以找回删除的文件

1.add trash dir

mkdir -p ~/.trash

2.add trash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
tee >>~/.bash_profile <<'EOF'
#add trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ru=undelfile
alias rc=cleartrash

#functions
undelfile()
{
mv -i ~/.trash/$@ ./
}

trash()
{
if [[ "$(echo $@)" =~ "-r" || "$(echo $@)" =~ "-rf" ]];then
echo "please cut -f/-rf, use rm"
else
mv $@ ~/.trash/
fi
}

cleartrash()
{
read -p "clear sure?[n|y]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /bin/rm -rf ~/.trash/*
}
EOF

source ~/.bash_profile

3.实战演示

# 删除文件,移动到回收站
rm/r xxx  

# 查看回收站文件
rl

# 恢复回收站内容到当前目录
ru

# 清空回收站
rc