Centos rm Recycle Bin
After linux rm deletes a file, it is troublesome to restore it. Even if it is restored, the file name format is changed to a string of numbers.
Modify the environment variable of the root user
Vi ~ /. Bashrc
Comment out the alias for line 1
# 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
Run the ll-a command to view the Directory and find that the directory is missing. trash, which is used to exist the deleted file.
Drwxr-xr-x. 2 root 4096 Jun 4. trash
Delete an object
[Root @ localhost ~] # Rm percona-xtrabackup_2.2.3.orig.tar.gz
View the Directory and find the deleted file in the recycle bin directory.
[Root @ localhost ~] # Ll. trash/
Total 33780
-Rw-r --. 1 root 34584359 Jun 2 percona-xtrabackup_2.2.3.orig.tar.gz
To clear the recycle bin file
Use the following command
[Root @ localhost ~] # Cleartrash
Clear sure? [N] y
Check again and find that it is empty.
[Root @ localhost ~] # Ll. trash/
Total 0
Although rm is defined by an alias, it can be an absolute path to delete files.
For example,/bin/rm 1.txt
It is not saved to the. trash directory.
If you need to define automatic cleanup of files deleted for 7 days
You can write a script.
#! /Bin/bash
Find/root/. trash-ctime 7-type f-name "*"-exec/bin/rm {}\;
In addition to the root user in Linux, other users need to log on to the server and want to use the recycle bin mechanism.
System environment variables can be modified.
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 common user test
Useradd
Set Password
Passwd
Log on to Linux
View the Directory and create the. trash directory.
[A @ localhost ~] $ Ll-
Total 24
Drwx ------. 3 a 4096 Jun 4 11: 45.
Drwxr-xr-x. 5 root 4096 Jun 4 ..
-Rw-r --. 1 a 18 Oct 16 2014. bash_logout
-Rw-r --. 1 a 176 Oct 16 2014. bash_profile
-Rw-r --. 1 a 124 Oct 16 2014. bashrc
Drwxrwxr-x. 2 a 4096 Jun 4 11: 45. trash
Create an empty file
[A @ localhost ~] $ Touch 1.txt
Delete an object
[A @ localhost ~] $ Rm 1.txt
View the recycle bin directory and find an additional file.
[A @ localhost ~] $ Ll. trash/
Total 0
-Rw-r --. 1 a 0 Jun 4 11: 45 1.txt
If you are uncomfortable with the. trash directory location, you can modify the environment variable and change it to another location. Ensure that the directory is writable.