linux上使用rm很危险,刚刚不小心删除了一个还有用的文件。因此我们可以把rm指令替换为mv,执行后把要删除的文件保留到一个目录下,定期清理就好了。 把下面的代码粘贴到你的.bashrc或。zshrc下。注意root下的也要粘贴。
# for rm {{# mkdir ~/.delete, when rm somethings ,mv them to hereif [ ! -d $HOME/.delete ]then mkdir $HOME/.deletefiunDoRm() { mv -i $HOME/.delete/$@ ./}toBackup(){ for thing in $@ do echo $thing | grep '^-' > /dev/null if [ ! $? = 0 ] then mv $thing $HOME/.delete echo mv $thing to ~/.delete, you can backup them fi done}cleanDelete(){ echo 'clear backup files?[y/N]' read confirm [ $confirm = 'y' ] || [ $confirm = 'Y' ] && /usr/bin/rm -rf $HOME/.delete/*}# rm somethingsalias rm=toBackup# see what in~/.delete nowalias lsdel='ls $HOME/.delete'# undoalias unrm=unDoRm# clean ~/.deletealias cleandel=cleanDelete# }}新闻热点
疑难解答