Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Replace rm command to prevent erroneous deletion

Shulou Source: shulou.com Published: 2022-06-01 06:09:22 10月01日 Update

Place erroneous deletion script:

/ usr/bin/remove.sh

#! / bin/bashPATH_CNT= "$#" TRASH_DIR= "$HOME/.trash" mkdir-p $TRASH_DIRmenu () {echo echo-e "\ t\ t\ tSys Options Menu\ n" echo-e "\ t1.Delete OK!" Echo-e "\ t2.Don't delete Into the recycle bin: $HOME/.trash "echo-e"\ t0.Exit menu\ n\ n "echo-en"\ t\ tEnter Options: "read-n 1 option} mvfunc () {for i in $@ do STAMP= `date +% Y% m% d% H% M% s`fileName= `basename $i`mv-f $I $TRASH_DIR/$fileName.$STAMP Echo done} rmfunc () {for i in $@ do STAMP= `date +% Y% m% d% H% M% s`basename $i` [- n $I] & & rm-rf $I $TRASH_DIR/$fileName.$STAMP echo done} while: domenucase $option in "1") Rmfunc $@ & & exit 0 ; "2") mvfunc $@ & & exit 0;; "0") break; *) echo "Sorry,wrong selection";; esacdone

3. Modify ~ / .bash_profile (personal preference file). If you want any user to modify it, add a global profile in / etc/profile.d/:

Such as / etc/profile.d/remove.sh

Alias rm='sh / usr/bin/remove.sh'

It will be started later when the user logs in or generates a new process.

4. Clean the dustbin regularly

Such as using crontab mechanism, such as 00 * rm-rf / home/username/.trash/*

5. Execution result

Test.py.2016062117521466502755

Tags: File user personal preference global garbage trash time mechanism result script process login configuration command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL Linux Shulou Information Apple