Detailed explanation of the implementation process and usage of the Linux Recycle Bin mechanism

Detailed explanation of the implementation process and usage of the Linux Recycle Bin mechanism

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.

#Delete a folder and the files will be moved to the Recycle Bin.

$rm filedirctory

#Delete a file

$rm file.txt

#Undo the deletion of file.txt

$ur file.txt

#Remove the filedirctory folder

$ur filedirctory

# List the recycle bin

$rl

#Empty the Recycle Bin

cleartrash

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:

/usr/bin/rm -rf

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:
  • Trash-Cli: Command-line Recycle Bin Tool on Linux
  • 101 scripts to create a Linux recycle bin script
  • Linux uses suid vim.basic file to achieve privilege escalation
  • Quickly solve the Chinese input method problem under Linux
  • Use MySQL to open/modify port 3306 and open access permissions in Ubuntu/Linux environment
  • Detailed explanation of commands to read and write remote files using Vim in Linux system
  • Solution to Linux server graphics card crash

<<:  Usage of mysql timestamp

>>:  Detailed explanation of mixins in Vue.js

Recommend

Solution to MySQL replication failure caused by disk fullness

Table of contents Case scenario Solving the probl...

How to use the Linux seq command

1. Command Introduction The seq (Sequence) comman...

30 excellent examples of color matching in web design

Today, this article has collected 30 excellent cas...

How to check whether a port is occupied in LINUX

I have never been able to figure out whether the ...

PNG Alpha Transparency in IE6 (Complete Collection)

Many people say that IE6 does not support PNG tra...

A brief discussion on how Tomcat breaks the parent delegation mechanism

Table of contents JVM Class Loader Tomcat class l...

How to use CSS to write different styles according to sub-elements

The effect we need to achieve: What is needed The...

Mysql practical exercises simple library management system

Table of contents 1. Sorting function 2. Prepare ...

Docker deployment and installation steps for Jenkins

First, we need a server with Docker installed. (I...

How to implement remote automatic backup of MongoDB in Linux

Preface After reading the previous article about ...

Teach you to create custom hooks in react

1. What are custom hooks Logic reuse Simply put, ...

Coexistence of python2 and python3 under centos7 system

The first step is to check the version number and...

General Guide to Linux/CentOS Server Security Configuration

Linux is an open system. Many ready-made programs...

A simple method to modify the size of Nginx uploaded files

Original link: https://vien.tech/article/138 Pref...

32 Typical Column/Grid-Based Websites

If you’re looking for inspiration for columnar web...