Home > System Tutorial > LINUX > body text

Introducing the enhancement of the recycle bin function of CentOS system

PHPz
Release: 2024-01-03 19:22:29
forward
777 people have browsed it

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!