Preface: rm under Linux system is irreversible. There is nothing wrong with the command design itself. The problem is that we are usually very confident and like to use rm -rf when executing. This is very dangerous. If the command is executed incorrectly or even the directory is executed incorrectly, it will cause a lot of trouble. At the least, it will lead to overtime work and waste of manpower and material resources. At the worst, it will affect the company's business and even lead to the risk of dismissal. The Recycle Bin mechanism under Windows is a very good strategy, but Linux does not have it. Then we can create one manually and execute it directly: mkdir -p ~/.Trash cat >>~/.bashrc<<EOF #add by caimengzhi at $(date +%F) for Linux trash start alias rm=trash alias rl='ls ~/.Trash' alias ur=undelfile undelfile() { mv -i ~/.Trash/\$@ ./ } trash() { mv \$@ ~/.Trash/ } cleartrash() { read -p "Clear trash?[n]" confirm [ \$confirm == 'y' ] || [ \$confirm == 'Y' ] && /usr/bin/rm -rf ~/.Trash/* } #add by caimengzhi at $(date +%F) for Linux trash end EOF source ~/.bashrc illustrate: 1. ~/.Trash is where deleted files and folders are moved to, that is, the Recycle Bin 2. \$confirm means to implement verification, which means that the last thing in the file is $confirm. Among them, \$@ is the same 3. The above function, to put it simply, is to rename the command rm. Use syntax: rm (delete), ur (undo), rl (list recycle bin), cleartrash (empty recycle bin) commands.
OK, that's the basic content. In essence, it just replaces the root user's rm command with the mv command. If the system has established other users, you also need to use that user to re-execute the above command. It depends on the situation. If you lose the root privilege, then the power of rm -rf is nothing to be afraid of. Of course, we also need to execute the regular rm command. How to do it? This is ok: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
>>: Detailed explanation of mixins in Vue.js
Table of contents Case scenario Solving the probl...
1. Command Introduction The seq (Sequence) comman...
Today, this article has collected 30 excellent cas...
I have never been able to figure out whether the ...
Many people say that IE6 does not support PNG tra...
Table of contents JVM Class Loader Tomcat class l...
The effect we need to achieve: What is needed The...
Table of contents 1. Sorting function 2. Prepare ...
First, we need a server with Docker installed. (I...
Preface After reading the previous article about ...
1. What are custom hooks Logic reuse Simply put, ...
The first step is to check the version number and...
Linux is an open system. Many ready-made programs...
Original link: https://vien.tech/article/138 Pref...
If you’re looking for inspiration for columnar web...