Linux運維小細節之回收站(二)

做者:張巖峯,轉載請註明出處     筆名:雲煙舊夢html

51CTO課程地址:https://edu.51cto.com/lecturer/12750547.html    Linux技術交流羣:1127825548linux


        上一章咱們講過了回收站的構建,固然咱們一步一步手動構建是很麻煩的,這裏張老師在這裏寫了一個腳本,一鍵構建回收站功能:
bash

        一鍵搭建linux回收站功能:
ide

        [root@localhost ~]# cat Recycling_bin.sh htm

        #!/bin/baship

        #####################ci

        # script name:zhangrem

        # qq:1754815191it

        # creation time:2020-02-04io

        # 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

        注意:仍是須要手動從新加載一下配置文件

相關文章
相關標籤/搜索