How to move files to the Recycle Bin using the RM command in Linux

Source: Internet
Author: User

Today, under the terminal, see my user directory has a ~ folder (Maven generation), to remove the recovery point space, habitual command RM-RF ~, a back car, suddenly think of time is too late, the world suddenly quiet, want to die heart have!

Yes, ~ specified is the current user's directory, my username is liyd, equivalent to the execution of Rm-rf/home/liyd, all the files are deleted. Tried a variety of Linux file recovery methods, are not ideal, ext4 format, back to the ratio is too small, but also in a lot of messy files to find the need, alas! Fortunately there are no particularly important files, the code is submitted by Git and SVN, and the loss is acceptable.

This time is ~, the next time if you knock another one may be more cups, after this lesson, think can have a way to delete the RM command files to the Recycle Bin, leave some mistake to delete regret, online A check, there really is.

Looked at, basically changed the concept, the RM command into the MV command, but can achieve the effect I want, but in the customary typing-r parameter will be reported an error, because the MV command does not have the-R parameter, the following is the method:

The principle is to create a hidden folder in the user's home directory ~/.trash as the garbage collection station.

The code is as follows:
Mkdir-p ~/.trash
VI ~/.BASHRC


Then write the following code to ~/.BASHRC and save it.

The code is as follows:
Alias rm= ' Trash '
Alias Rl= ' Trashlist '
Alias ur= ' Undelfile '
#替换rm指令移动文件到 ~/.trash/.
Trash ()
{
MV [email protected] ~/.trash/
}
#显示回收站中垃圾清单
Trashlist ()
{
Echo-e "33[32m==== garbage Lists in ~/.trash/====33[0m"
ECHO-E "\a33[33m----Usage------33[0m"
Echo-e "\a33[33m-1-use ' cleartrash ' to clear all garbages in ~/.trash!!! 33[0m "
Echo-e "\a33[33m-2-use ' ur ' to mv the file in garbages to current DIR!!! 33[0m "
Ls-al ~/.trash
}
#找回回收站相应文件
Undelfile ()
{
Mv-i ~/.trash/[email protected].
}
#清空回收站
Cleartrash ()
{
Echo-ne "\a33[33m!!! Clear all garbages in ~/.trash, sure? [y/n]33[0m]
Read confirm
if [$confirm = = ' y '-o $confirm = = ' Y ']; then
/BIN/RM-RF ~/.trash/*
/BIN/RM-RF ~/.trash/.* 2>/dev/null
Fi
}


Refresh the environment configuration below the command line to take effect:

The code is as follows:
SOURCE ~/.BASHRC

How to move files to the Recycle Bin using the RM command in Linux

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.