rm-rf use with caution
There are too many commands to type on the Linux virtual host. If you often walk on the beach, your shoes will inevitably get wet
Tomorrow, I made a mistake and typed the wrong command, and lost the folder I originally wanted to keep to rm-rf
All the hard work of the past few days has been lost. Damn it, I feel like dying.
After trying Baidu, Google and other methods to no avail, hey, let’s study how to retrieve it later
Some lessons:
1.rm, especially before rm-rf, be careful, think twice, or rewrite the command directly
2. Make a good backupHow to recover files deleted from the Recycle Bin in Linux, there is a convenient backup script
3. Make scheduled backups. There is a master who can create a scheduled script and execute it by yourself every night. Even if you delete it by mistake, you won’t be so frustrated.
First of allHow to recover files deleted from the Recycle Bin in LinuxIs there a future for learning Linux and setting up a Recycle Bin
Add .bashrc or .bash_profile under ~
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 execution
rm is equivalent to executing mv
Note: There is no rm-rf at this time
Deleted files will appear in .trash
can be restored
urfilename
This brings up a problem, how to delete things in the recycle bin, this is why rm is useless here
Continue to add functions under .bashrc just now
cleartrash() { read -p "clear sure?[n]" confirm [ $confirm == 'y' ] || [ $confirm == 'Y' ]&& /usr/bin/rm -rf ~/.trash/* }
$..bashrc
Afterwards, if you want to empty the Recycle Bin
$cleartrash will do
The backup script is working
Includes packaged and compressed fast backup scripts and midnight scheduled backup scripts
I haven’t learned how to delete and repair files under Linux yet, hey
Blood lessons, take precautions
The above is the detailed content of Use the rm command carefully. If you accidentally type the wrong one, your efforts for several days will be wasted.. For more information, please follow other related articles on the PHP Chinese website!