Home > System Tutorial > LINUX > body text

Use the rm command carefully. If you accidentally type the wrong one, your efforts for several days will be wasted.

PHPz
Release: 2024-01-26 21:45:30
forward
1081 people have browsed it

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

linux回收站还原_linux回收站命令行删除_linux如何恢复回收站删除的文件

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/
}
Copy after login

This is execution

rm is equivalent to executing mv

linux回收站命令行删除_linux如何恢复回收站删除的文件_linux回收站还原

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/*
}
Copy after login

$..bashrc

linux如何恢复回收站删除的文件_linux回收站命令行删除_linux回收站还原

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!

Related labels:
source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!