How to put the files deleted by the Linux rm command into the garbage bin

  

Because the files deleted by the rm command are not put into the garbage bin, they cannot be restored. The following small series introduces a method to replace the Linux rm. The command method, so that the files deleted by the rm command are put into the garbage box, so that the files deleted by mistake can be recovered, and the learning can be done together.

Method:

1. Create a directory under /home /username /directory named: .trash

2. at /home /username /In the tools/directory, create a new shell file named: remove.sh

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, add a line

alias rm=“sh /home/username/tools/remove.sh”

Use our self-built remove.sh instead of the rm command

4. Set up the crontab to empty the trash box periodically, eg:

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

Empty the trash at 0 o'clock every day

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

The above is the file deleted by the Linux rm command. The method of entering the trash can is introduced. After replacing the rm command with the method described in this article, the file is deleted in time. Don't worry, just go back to the trash.

Copyright © Windows knowledge All Rights Reserved