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

Mysql dynamically updates the database script example explanation

The specific upgrade script is as follows: Dynami...

MySQL randomly extracts a certain number of records

In the past, I used to directly order by rand() t...

Introduction to the use and advantages and disadvantages of MySQL triggers

Table of contents Preface 1. Trigger Overview 2. ...

Detailed process of decompressing and installing mysql5.7.17 zip

1. Download address https://dev.mysql.com/downloa...

MYSQL database basics - Join operation principle

Join uses the Nested-Loop Join algorithm. There a...

Detailed explanation of the misunderstanding between MySQL and Oracle

Table of contents Essential Difference Database s...

How to set npm to load packages from multiple package sources at the same time

Table of contents 1. Build local storage 2. Creat...

Datagrip2020 fails to download MySQL driver

If you cannot download it by clicking downloadlao...

MySQL master-slave replication principle and practice detailed explanation

Table of contents Introduction effect principle f...

How to adjust the log level of nginx in Docker

Table of contents Intro Nginx Dockerfile New conf...

js to achieve simple front-end paging effect

Some projects have relatively simple business, bu...

Navicat multiple ways to modify MySQL database password

Method 1: Use the SET PASSWORD command First log ...

mysql group_concat method example to write group fields into one row

This article uses an example to describe how to u...