Linux Install Recycle Bin function trash-cli can prevent accidental deletion of files

Source: Internet
Author: User
Tags redis

How do we accidentally execute the following command on a Linux system?

RM-RF/

If we mistakenly delete the document, how to recover it?

This time, our protagonist Trash-cli is about to play, he has achieved similar windows in the Recycle Bin function.

Trash-cli

TRASH-CLI's project address TRASH-CLI HTTPS://GITHUB.COM/ANDREAFRANCIA/TRASH-CLI

I. Installation

TRASH-CLI installation is simple.

Cd/tmp
Https://github.com/andreafrancia/trash-cli
CD TRASH-CLI
sudo python setup.py install

After the installation is successful, our system has the following tools

➜~ Ll/usr/bin/|grep Trash
-rwxr-xr-x 1 root root 123 May 19:38 Trash
-rwxr-xr-x 1 root root 125 May 19:38 Trash-empty
-rwxr-xr-x 1 root root 124 May 19:38 trash-list
-rwxr-xr-x 1 root root 123 May 19:38 trash-put
-rwxr-xr-x 1 root root 127 May 19:38 Trash-restore
-rwxr-xr-x 1 root root 122 May 19:38 trash-rm

Function description

Trash = = Trash-put = = Delete
Trash-empty empty.
Trash-list List Recycle Bin
Trash-restore Recovery file
TRASH-RM Delete the specified file in the Recycle Bin

Ii. How to use
Replace command

For security's sake, let's replace the RM command with the Trash

Vim/etc/bashrc

Replace the system Delete command by adding the following.

According to the author's readme file, it is recommended that RM be replaced with no replacement, the following replacement void.
Alias log= ' Cd/var/log ' # safely remove alias rm= ' Trash ' # list Recycle Bin alias rl= ' Trash-list '

Original author

Can I alias rm to Trash-put?
Can but you shouldn ' t. In the early I thought it is good idea did that but now I changed my mind.
The interface of Trash-put seems to is compatible with RM it has a different semantic that'll cause you. For example, while RM requires-r for deleting directories trash-put.
But Sometimes I forgot to use trash-put, really can ' t I?
You could alias RM to something that would remind you to don't use it:
The alias rm= ' Echo ' is not the command of your are looking for. " False
If you are really want use RM simply prepend a slash:
\RM File-without-hope
Note that Bash aliases are used only in interactive shells, so using this alias should not interfere with scripts that exp ECTS to use RM.

So the new replacement is

# Pre-use RM Confirmation
The alias rm= ' Echo ' is not the command of your are looking for. If you are really want use RM simply prepend a slash "; False

If you perform RM later, the following conditions will occur

➜~ RM
This isn't the command you are looking for. If you are really want use RM simply prepend a slash

In the future if you really want to delete, please use the \rm really useless files, and use trash need to delete the file.

When finished enter SOURCE/ETC/BASHRC is the modified alias is in effect.
Common operations

# safely removed
RM./*

# View Recycle Bin
➜/tmp RL
2015-05-28 19:59:54/tmp/redis-stable

# Empty the Recycle Bin
Trash-empty

# empty files that were put into the Recycle Bin 10 days ago
Trash-empty 10

# Restore files
➜/tmp Trash-restore
0 2015-05-28 19:59:54/tmp/redis-stable
What file to restore [0..0]: Enter the corresponding ordinal restore


Now we can finally safely delete the document, if mistakenly deleted, you can easily find back.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.