Recommended reading: The recovery method for Linux RM command mistakenly deleted files
1. Create a new directory under the/home/username/directory, named:. Trash
2. Under the/home/username/tools/directory, create a new shell file named: remove.sh
Copy Code code as follows:
para_cnt=$#
Trash_dir= "/home/username/.trash"
For i in $*; Todo
stamp= ' Date +%s '
Filename= ' basename $i '
MV $i $TRASH _dir/$fileName. $STAMP
Done
3. Modify ~/.BASHRC, add one line
Copy Code code as follows:
Alias rm= "Sh/home/username/tools/remove.sh"
Replace the RM command with our own built remove.sh
4. Set crontab, periodically empty the trash, such as:
Copy Code code as follows:
0 0 * * * rm-rf/home/username/.trash/*
Empty trash bins at 0 a day.
5. Source ~/.BASHRC make replacement immediately effective
After the above steps, the files that perform RM deletions are placed in the dumpster. If you mistakenly delete, you can recover from it.
The above content to introduce the Linux command to replace RM command to prevent accidental deletion of the relevant knowledge, I hope to help you learn.