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