ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux运维小细节之回收站(二)

2021-03-20 18:51:46  阅读:175  来源: 互联网

标签:运维小 bin false ----- Linux action trash true 回收站


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

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

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


标签:运维小,bin,false,-----,Linux,action,trash,true,回收站
来源: https://blog.51cto.com/12760547/2666774

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有