How to put files deleted by the Linux RM command into a trash bin

Source: Internet
Author: User

Because the RM command deleted files will not be put into the garbage bin, so can not be restored, the following small series to introduce a method, by replacing the Linux RM command method, so that the RM command deleted files into the garbage bin.

Method:

1. Create a new directory under the/home/username/directory, named:. Trash

2. In the/home/username/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"

Replace the RM command with our self-built remove.sh

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

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

Empty the trash bin at 0 o ' Day

5. Source ~/.BASHRC make the substitution take effect immediately

The above is the Linux RM command mistakenly deleted file into the garbage bin method introduced, using the method described in this article to replace the RM command, timely files are mistakenly deleted also do not worry, to the garbage bin recovery.

Transferred from: http://www.xitongzhijia.net/xtjc/20150306/40342.html

How to put files deleted by the Linux RM command into a trash bin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.