rm防误删

备份

\cp ~/.bashrc{,.bak}

创建回收目录

mkdir -p ~/.trash
cat ~/.bashrc

# .bashrc

# User specific aliases and functions

#alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e[0m\]]\\$"

#rm防误删
alias rm=trash
alias rl='ls -al ~/.trash/'
trash()
{
    mv $@ ~/.trash/
    echo "已经移动到回收站,可rl查看"
    echo "cltr清除回收站,默认保存30天"
    echo "retr可恢复误删除"
}
retr ()
{
    mv -i ~/.trash/$@ ./
}
cltr ()
{
    find ~/.trash/ -mtime +30 -type f -name "*" -exec \rm -rf {} \;
}

生效

source ~/.bashrc
添加新评论