Linux recycle bin [rewrite rm to prevent files from being recovered by mistake]

Source: Internet
Author: User
Rm-rf is more careful when using commands. it often goes by the river. it is inevitable that the shoes will be wet. yesterday, a wrong hand, wrong command, put the folder you originally wanted to keep to rm-rf for a few days of painstaking efforts, rely on, and the heart of death has gone through Baidu, google, and try to be fruitless, ah, how can I find it later... capital

 

Rm-rf use with caution

 

The command has been knocked a lot. it often goes by the river, and it is inevitable that the shoes will be wet.

 

Yesterday, by mistake, I typed the wrong command and gave the folder to rm-rf.

 

A few days of hard work, relying on, the heart of death

 

 

Baidu, google, and fail to get it back.

 

 

Lessons:

 

1. be careful before rm, especially rm-rf, or simply rewrite the command.

 

2. make backup and have convenient backup scripts

 

3. make a regular backup. one of our predecessors has a regular script and runs it on a regular basis every day. even if a mistake is deleted, it will not be so miserable.

 

 

First, create a recycle bin.

 

In ~ Add. bashrc or. bash_profile

 

 

Mkdir-p ~ /. Trash

Alias rm = trash

Alias r = trash

Alias rl = 'ls ~ /. Trash'

Alias ur = undelfile

Undelfile ()

{

Mv-I ~ /. Trash/$ @./

}

Trash ()

{

Mv $ @~ /. Trash/

}

 

This is the execution

Rm is equivalent to executing mv.

 

Note: rm-rf is already available.

 

The deleted file will appear in. trash.

 

Can be recovered

 

 

Ur filename

 

 

This poses a problem. how to delete the items in the recycle bin? this is a useful post-rm here.

 

 

 

Add a function under. bashrc just now.

 

 

Cleartrash ()

{

Read-p "clear sure? [N] "confirm

[$ Confirm = 'y'] | [$ confirm = 'y'] &/usr/bin/rm-rf ~ /. Trash /*

}

 

$ .. Bashrc

Then, if you want to clear the recycle bin

 

$ Cleartrash.

 

 

Backup Script in process

 

Including compress, fast backup, and midnight scheduled backup.

 

Delete files in linux and fix them. Currently, I have learned how to delete files.

 

 

Lessons learned from blood and prevention

From: wklken's note

Related Article

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.