Home  >  Article  >  Operation and Maintenance  >  How to prevent accidental deletion in Linux

How to prevent accidental deletion in Linux

王林
王林forward
2023-05-14 13:16:061446browse

1. Create a new directory in the /home/username/ directory and name it: .trash

2.. Create a new shell file in the /home/username/tools/ directory and name it: remove.sh

Copy code The code is as follows:

para_cnt=$#
trash_dir="/home/username/.trash"
for i in $*; do
stamp=`date +%s`
filename=`basename $i`
mv $i $trash_dir/$filename.$stamp
done

3. Modify ~/.bashrc and add a line

Copy code The code is as follows:

alias rm="sh /home/username/tools/remove.sh"

Use Our self-built remove.sh replaces the rm command

4. Set up crontab and empty the trash can regularly, such as:

Copy code The code is as follows:

0 0 * * * rm -rf /home/username/.trash/*

Clear it at 0 o'clock every day Trash bin

5. source ~/.bashrc makes the replacement take effect immediately

After the above steps, the files deleted by executing rm will be placed in the trash bin. If deleted by mistake, you can recover from it.

The above is the detailed content of How to prevent accidental deletion in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete