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

【Linux系统】修改Linux系统 rm指令,避免误删文件

2015-07-06 16:20 507 查看
#cd ~

# vim .bashrc // 添加如下内容

# Redefine rm cmd to avoid accidental deletion -- 20150706pm_lile add
if [ ! -d ~/.trash ]; then
        mkdir -p ~/.trash
fi

alias rm=trash    
alias r=trash    
alias rl='ls ~/.trash'  
alias ur=undelfile  
undelfile()  
{  
  mv -i ~/.trash/$@ ./  
}  
trash()  
{  
  mv -b $@ ~/.trash/  
}
cleartrash()  
{  
    read -p "clear sure?
" confirm  
    [ $confirm == 'y' ] || [ $confirm == 'Y' ]  && /usr/bin/rm -rf ~/.trash/*  
}


# source ~/.bashrc // 或者 关闭终端 再打开亦可

自此, rm 删除的文档都会移动到 ~/.trash 文件夹;

若需要清空自定义回收站, cleartrash 即可。

参考文章: http://blog.csdn.net/wklken/article/details/6898590
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: