Linux Commands replace RM command to prevent accidental deletion of _linux

Source: Internet
Author: User

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.

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.