rm 刪除檔案到垃圾箱

來源:互聯網
上載者:User

#作者:閆曉峰

#E-mail:xiaofeng_yan2004@126.com

#將下列的代碼添加到使用者下的.bashrc中,這樣這段代碼就可以發揮作用了。如果是在終端輸入的那麼輸入代碼後退出終端在開啟終端,這段代碼就生效了。有一部分是參照網上的代碼。

 

#具體功能如下:

#rm

#rm -f

#rm -r

#rm -rf

#rl 查看資源回收筒的內容

#rc 清空資源回收筒

#ur 後面加參數恢複資源回收筒的檔案到目前的目錄下

mkdir -p ~/.trash
alias rm=trash
alias rc=clean_trash
alias rl='ls ~/.trash'
alias ur=undelfile

undelfile()
{
    if test -z "$1"
    then
        echo -e "/E[32;40mPleae input recovery file or directory name"
        tput sgr0
    else
       until [ -z "$1" ]
       do
           mv -i  ~/.trash/$1 ./
           shift
       done
    fi
}

trash()
{
    if [ "$1" == "-f" -o "$1" == "-rf" -o "$1" == "-r" ]; then
        until [ -z "$2" ] 
        do
            mv $2 ~/.trash/
            shift
        done
    else
        mv $@ ~/.trash
    fi
}

clean_trash()
{
    echo -e "/E[32;40mdo you want to empty Recycle Bin,Please input /"yes/" or /"no/""
    read CLEAN
    if [ "$CLEAN" == "y" -o "$CLEAN" == "yes" ]; then
        /bin/rm -rf ~/.trash/*
        echo -e "/E[32;40mRecycle Bin is cleared!"
        tput sgr0
    else
        echo -e "/E[31;40mdon't clean trash"
    fi
    tput sgr0

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

#修改上述代碼,增加如果資源回收筒裡已經有了你刪除的檔案當再次刪除同樣的檔案時,原來的檔案將變成檔案名稱+替換的時間。#

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

#trash funnction
#author: Yan Xiaofeng
mkdir -p ~/.trash
alias rm=trash
alias rc=clean_trash
alias rl='ls ~/.trash'
alias ur=undelfile

#CURRENT_FILE_NUM=`ls -l | wc -l`
#FILE_REMOVED=0
#CURRENT_DIR=`pwd`
#i=0
TRASH=~/.trash
undelfile()
{
        if test -z "$1"
        then
                        echo -e "/E[32;40mPleae input recovery file or directory name"
                        tput sgr0
        else
                until [ -z "$1" ]
                do
                        mv -i  ~/.trash/$1 ./
                        shift
                done
        fi
}

trash()
{
        if [ "$1" == "-f" -o "$1" == "-rf" -o "$1" == "-r" ]; then
        until [ -z "$2" ]
        do
                if [ -e "$TRASH/$2" ]; then
                        mv $TRASH/$2 $TRASH/`basename $2`-`date +%F`-`date +%R`-`date +%S`
                fi
                        mv $2 $TRASH
                shift
        done
        else
        until [ -z "$1" ]
        do
                if [ -e "$TRASH/$1" ]; then
                        mv $TRASH/$1 $TRASH/`basename $1`-`date +%F`-`date +%R`-`date +%S`
                fi
                        mv $1 $TRASH
                shift
        done
        fi
}

clean_trash()
{
        read -p "`echo -e "/E[32;40mDo you want to empty Recycle Bin,Please input /"yes/" or /"no/":/E[35;40m"`" CLEAN
       # read CLEAN
        if [ "$CLEAN" == "y" -o "$CLEAN" == "yes" ]; then
                /bin/rm -rf ~/.trash/*
                echo -e "/E[32;40mRecycle Bin is cleared!"
                tput sgr0
        else
                echo -e "/E[31;40mDon't clean trash"
        fi
                tput sgr0
}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.