Linux recycle bin [rewrite RM to prevent files from being recovered by mistake]-wklken notes-blog channel-csdn. net
Linux recycle bin [rewrite RM to prevent files from being recovered by mistake] Category: 04-linux Read by 2275 Comment (1) Favorites Report Linux script Google Baidu
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
[Python] View plaincopyprint?
- mkdir-P ~ /. Trash
- alias Rm = trash
- alias r = trash
- alias RL = 'ls ~ /. Trash '
- alias ur = undelfile
- undelfile ()
- {
- MV-I ~ /. Trash/$ @./
- }
- trash ()
- {
- MV $ @~ /. Trash/
- }
Mkdir-P ~ /. Trashalias Rm = trash alias r = trash alias RL = 'ls ~ /. Trash 'Alias ur = undelfileundelfile () {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.
[Python] View plaincopyprint?
- Cleartrash ()
- {
- Read-P"Clear sure? [N]"Confirm
- [$ Confirm ='Y'] | [$ Confirm ='Y'] &/Usr/bin/Rm-RF ~ /. Trash /*
- }
Cleartrash () {read-P "Clear sure? [N] "Confirm [$ confirm = 'y'] | [$ confirm = 'y'] & amp;/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