作者:张岩峰,转载请注明出处     笔名:云烟旧梦

51CTO课程地址:https://edu.51cto.com/lecturer/12750547.html    Linux技术交流群:1127825548


        上一章我们讲过了回收站的构建,当然我们一步一步手动构建是很麻烦的,这里张老师在这里写了一个脚本,一键构建回收站功能:

        一键搭建linux回收站功能:

        [root@localhost ~]# cat Recycling_bin.sh 

        #!/bin/bash

        #####################

        # script name:zhang

        # qq:1754815191

        # creation time:2020-02-04

        # update time:2020-02-04

        # version:1.0

        #####################


        . /etc/init.d/functions

        sleep 2

        LANG=en


        # Set up a recycling bin

        mkdir -p ~/.trash &>/dev/null

        if [ -d ~/.trash ]

            then

                cd ~/.trash

                action "Establish ~/.trash" /bin/true

            else

                action "Establish ~/.trash" /bin/false

                exit

        fi


        # Configuration the recycle bin master feature


        echo "##### Recycle Stop Commaand Help #####"


        cat >> ~/.bash_profile <<EOF

        alias rm=trash

        alias r=trash

        alias rl='ls ~/.trash'

        alias ur=undelfile


        undelfile()

        {

          mv -i ~/.trash/\$@ ./

        }


        trash()

        {

          mv \$@ ~/.trash/

        }

        EOF


        if [ $? = 0 ]

          then

            action "rm  -----  remove" /bin/true

            action "rl  -----  View trash content" /bin/true

            action "ur  -----  Recovering specified files" /bin/true

          else

            action "rm  -----  remove" /bin/false

            action "rl  -----  View trash content" /bin/false

            action "ur  -----  Recovering specified files" /bin/false

            exit

        fi


        # Configuration the trash can-empty function

        cat >> ~/.bashrc <<EOF

        cleartrash()

        {

        read -p "clear sure?[n]" confirm

        [ \$confirm == "y" ] || [ \$confirm == "Y" ] && /usr/bin/rm -rf ~/.trash/*

        }


        $..bashrc

        EOF


        if [ $? = 0 ]

          then 

            action "cleartrash  -----  Emptying the recycle bin" /bin/true

          else 

            action "cleartrash  -----  Emptying the recycle bin" /bin/false

            exit

        fi

        sleep 2

        [root@localhost ~]# . ~/.bash_profile

        注意:还是需要手动重新加载一下配置文件


©著作权归作者所有:来自51CTO博客作者ssdsscvsscg的原创作品,如需转载,请注明出处,否则将追究法律责任

每一份赞赏源于懂得

赞赏

0人进行了赞赏支持

更多相关文章

  1. Oracle Linux 7.9+Oracle 12c+ASM安装文档--4、添加ASM磁盘组
  2. Oracle Linux 7.9+Oracle 12c+ASM安装文档--5、数据库软件安装
  3. 12c执行统计信息收集报ORA-12012 ORA-20001 ORA-06512
  4. dock 无法正常启动
  5. 顺序栈(C语言,静态栈)
  6. mysql数据查询关于字段为100000-130000-130400-130426的数据格式
  7. Elasticsearch 之 监控告警通知
  8. shell实现MySQL全量备份
  9. mysql查询指定字段以","拼接字符串作为结果返回

随机推荐

  1. 一个有意思的学习python的方式
  2. 从Django开发服务器的根服务提供静态文件
  3. Python 字典 pop() 方法
  4. 细菌觅食算法-python实现
  5. Python网页静态爬虫
  6. Python学习系列(六)(模块)
  7. 校招录取之后前往公司实习,现在感觉自己前
  8. 如何将dict转换为spark map输出
  9. 当使用一个传送到另一个的python文件时,我
  10. matplotlib绘制符合论文要求的图片