Introducing the enhancement of the recycle bin function of CentOS system
After linux rm deletes a file, it is more troublesome to restore it. Even if it is restored, the file name format becomes a string of numbers.
Modify the environment variables of the root user
vi ~/.bashrc
Comment the alias of line 5
#alias rm='rm -i'
Add the following content to the last line
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
mv -i ~/.trash/$@ ./
}
trash()
{
mv $@ ~/.trash/
}
cleartrash()
{
read -p "clear sure?[n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /bin/rm -rf ~/.trash/*
}
Reload environment variables
source ~/.bashrc
Use the command ll -a to view the directory and find that there is an additional directory .trash. This directory is used to store deleted files
drwxr-xr-x. 2 root root 4096 Jun 4 11:31 .trash
Delete a file
[root@localhost ~]# rm percona-xtrabackup_2.2.3.orig.tar.gz
Check the directory and find that the deleted files are in the recycle bin directory
[root@localhost ~]# ll .trash/
total 33780
-rw-r--r--. 1 root root 34584359 Jun 2 09:39 percona-xtrabackup_2.2.3.orig.tar.gz
If you need to empty the recycle bin files
Use the following commands
[root@localhost ~]# cleartrash
clear sure?[n]y
Checked again and found it was empty.
[root@localhost ~]# ll .trash/
total 0
Although rm is defined with an alias, you can use an absolute path to delete files
For example/bin/rm 1.txt
It will not be saved to the .trash directory.
If you need to define automatic cleaning of files deleted within 7 days
You can write a script
#!/bin/bash
find /root/.trash -ctime 7 -type f -name "*" -exec /bin/rm {} \;
Then just call it in the task plan.
If there are other Linux users who need to log in to the server in addition to the root user, we also want them to use the recycle bin mechanism
Can modify system environment variables
vi /etc/profile
Add the last line
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
mv -i ~/.trash/$@ ./
}
trash()
{
mv $@ ~/.trash/
}
cleartrash()
{
read -p "clear sure?[n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /bin/rm -rf ~/.trash/*
}
Reload environment variables
source /etc/profile
Create a normal user test
useradd a
set password
passwd a
Login to Linux
Check the directory and find that the .trash directory will be created
[a@localhost ~]$ ll -a
total 24
drwx------. 3 a a 4096 Jun 4 11:45 .
drwxr-xr-x. 5 root root 4096 Jun 4 11:44 ..
-rw-r--r--. 1 a a 18 Oct 16 2014 .bash_logout
-rw-r--r--. 1 a a 176 Oct 16 2014 .bash_profile
-rw-r--r--. 1 a a 124 Oct 16 2014 .bashrc
drwxrwxr-x. 2 a a 4096 Jun 4 11:45 .trash
Create an empty file
[a@localhost ~]$ touch 1.txt
Delete Files
[a@localhost ~]$ rm 1.txt
Check the recycle bin directory and find that there is an extra file
[a@localhost ~]$ ll .trash/
total 0
-rw-rw-r--. 1 a a 0 Jun 4 11:45 1.txt
If you feel unhappy with the location of the .trash directory, you can modify the environment variable to another location, and make sure the directory is writable.
The above is the detailed content of Introducing the enhancement of the recycle bin function of CentOS system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

1. The Origin of .NETCore When talking about .NETCore, we must not mention its predecessor .NET. Java was in the limelight at that time, and Microsoft also favored Java. The Java virtual machine on the Windows platform was developed by Microsoft based on JVM standards. It is said to be the best performance Java virtual machine at that time. However, Microsoft has its own little abacus, trying to bundle Java with the Windows platform and add some Windows-specific features. Sun's dissatisfaction with this led to a breakdown of the relationship between the two parties, and Microsoft then launched .NET. .NET has borrowed many features of Java since its inception and gradually surpassed Java in language features and form development. Java in version 1.6

Software preparation I am using a virtual machine with CentOS-6.6, with the host name repo. Refer to the steps to install a Linux virtual machine in Windows, I installed JDK in that virtual machine, refer to the guide to installing JDK in Linux. In addition, the virtual machine is configured with a key-free login itself, and the settings for configuring key-free login between each virtual machine are referenced. The download address of Hadoop installation package is: https://mirrors.aliyun.com/apache/hadoop/common/. I am using hadoop 2.6.5 version. Upload the Hadoop installation package to the server and unzip [root@repo~]#tarzxv

Integrating Postman applications on CentOS can be achieved through a variety of methods. The following are the detailed steps and suggestions: Install Postman by downloading the installation package to download Postman's Linux version installation package: Visit Postman's official website and select the version suitable for Linux to download. Unzip the installation package: Use the following command to unzip the installation package to the specified directory, for example /opt: sudotar-xzfpostman-linux-x64-xx.xx.xx.tar.gz-C/opt Please note that "postman-linux-x64-xx.xx.xx.tar.gz" is replaced by the file name you actually downloaded. Create symbols

Optimizing the performance of Hadoop distributed file system (HDFS) on CentOS systems can be achieved through a variety of methods, including adjusting system kernel parameters, optimizing HDFS configuration files, and improving hardware resources. The following are detailed optimization steps and suggestions: Adjust the system kernel parameters to increase the limit on the number of files opened by a single process: Use the ulimit-n65535 command to temporarily adjust. If it needs to take effect permanently, please edit the /etc/security/limits.conf and /etc/pam.d/login files. Optimize TCP parameters: Edit /etc/sysctl.conf file, add or modify the following content: net.ipv4.tcp_tw

Customize the GitLab interface on CentOS system to easily create a personalized workspace! The following steps will guide you how to change the interface language and customize the homepage style: Interface language settings Log in to GitLab: Access your GitLab server address in your browser and log in. Access settings: Click on your user avatar in the upper right corner and select "Settings". Go to User Interface Settings: In the menu on the left, find "Preferences" and select "UserInterface". Select language: In the "User Interface" drop-down menu, select "Chinese(Simplified)",

There are many ways to back up HBase data on CentOS system. Here are some commonly used backup methods: HBase's own backup tool HBaseShell: You can use hbaseshell to perform backup operations manually. First, make sure you are connected to HBaseShell. Then, execute the following command: hbasecopy_table'source_table''destination_table',{COPY_TO'file:///pa

HBase's resource requirements on CentOS mainly cover hardware, operating system, and HBase-specific configuration parameters. The following is the detailed guidance: Hardware Requirements Processor: It is recommended to choose a 64-bit high-performance processor, such as IntelCorei7 or i9, and AMDRyzen9. Memory: It is recommended to configure at least 8GB of memory for HBase metadata storage and data cache. Hard disk: It is recommended to use at least 1TB of storage space, and it is recommended to use NVMeSSD to improve read and write performance. Network: It is recommended to configure high-speed network devices, such as Gigabit Network Cards, to ensure network bandwidth and low latency. Operating system optimization ensures that the system runs on a 64-bit operating system. Disable swap partition (replace vm.swa

Guide to Installation, Switching and Management of Java Versions in CentOS Systems In the CentOS environment, especially when multiple projects coexist, it is crucial to efficiently manage different Java versions. This article will explain in detail the installation, switching and management methods of Java versions in CentOS system. Java version installation uses yum to install system update: first update the system package: sudoyumupdate-y install the specified JDK version: For example, install OpenJDK8 and OpenJDK11: sudoyuminstalljava-1.8.0-openjdk-devel-ysudoyumi
