Disable RM command, use MV command to set up Recycle Bin for Linux

Source: Internet
Author: User

Convert RM command to MV Command, cannot use the-R parameter, will report an error, because the MV command does not have the-R parameter, the following is the method:

    • Create a hidden folder in the user's home directory ~/.trash as the garbage collection station
      [[email protected] shellXT]# mkdir -p ~/.trash
    • Write a script

#设置别名, RM is delete file, RL is view Recycle Bin, ur is recovery file
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
}

- 在命令行下面刷新一下环境配置,即可生效:

[Email protected] ~]# source ~/.BASHRC

- source命令的作用就是用来执行一个脚本,那么:source a.sh 同直接执行 ./a.sh 有什么不同呢,比如你在一个脚本里export $KKK=111 ,如果你用./a.sh执行该脚本,执行完毕后,你运行 echo $KKK ,发现没有值,如果你用source来执行 ,然后再echo ,就会发现KKK=111。因为调用./a.sh来执行shell是在一个子shell里运行的,所以执行后,结构并没有反应到父shell里,但是source不同它就是在本shell中执行的,所以可以看到结果

Disable RM command, use MV command to set up Recycle Bin for 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.