Let's get ourselves a recycling station and play.

Source: Internet
Author: User
Tags aliases

See a post today, tell me how to recover the data after it was mistakenly deleted. In the back of the thread found a more interesting thing, his exact words are like this:

I thought it was fun, so I decided to try it out myself.

First to build a directory to do the Recycle Bin, I chose to build a trash hidden folder in the root directory as the Recycle Bin: mkdir/.trash

Take a look at the established Recycle Bin: ll-a/|grep. Trash

Then I checked the MV usage: Man mv. Inside, there is such a parameter

This makes it obvious that I need to replace "rm *" with "mv-t/.trash-i *" And then I'm done. Since you are prepared to define your own commands, of course, Alias:alias rm= ' mv-t/.trash-i '

Then we look at the list of alias: Alias This is the new one added.

Let's try it. Create a new file: Touch test.test, then delete it with RM: RM test.test. LS view, found that test.test is really missing, then is not moved to the Recycle Bin "/.trash", go to see it: LS/.trash sure in the Recycle Bin.

At this point, the functionality has been implemented. But think of a question, what if I really want to delete a file? I try to delete files from the Recycle Bin: RM/.trash/test.test get boost MV: "/.trash/test.test" and "/.trash/test.test" are the same file. This can be troublesome, is it possible to delete files every time only through the/bin/rm to achieve it? Forget it, pound, simply add a custom command: Alias rrm= '/bin/rm-i ' cannot be written as ' rrm= ' rm-i ' because RM has been replaced with ' mv-t/.trash-i '. Then let's try the RRM directive: RRM/.trash/test.test Enter y acknowledgment and finally successfully deleted the Test.test file.

Alias instruction is a single time, the next time the power off after the shutdown, in order to ensure the next power-on command to maintain, we can modify the ~/.BASHRC file. The BASHRC file has the phrase "User specific aliases and functions", We can write the aliases we want to define in this file. The original alias rm= ' Rm-i ' in the file is commented out, plus alias rrm= '/bin/rm-i ' and alias rm= ' Mv-t/.trash-i ' two sentences. OK, now this function will be retained forever ~ ~

Let's get ourselves a recycling station and play.

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.