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# }}新聞熱點
疑難解答