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

How to prevent accidental deletion in Linux

王林
Release: 2023-05-14 13:16:06
forward
1506 people have browsed it

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
Copy after login

3. Modify ~/.bashrc and add a line

Copy code The code is as follows:

alias rm="sh /home/username/tools/remove.sh"
Copy after login

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/*
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template