WindSpirit

一个啥都知道但是啥也不会的小白程序员

bash回收站

通过替换rm命令使被删除的文件或文件夹被移动到~/.delete/日期文件夹,方便恢复

可以定期手动删除.delete文件夹或通过额外配置定期删除减少空间占用

# for rm {{

del_time=$(date +%H%M%S)
bak_date=$(date +%Y%m%d)

checkDelDir ()
{
    if [ ! -d $HOME/.delete ]
    then
        mkdir $HOME/.delete
    fi

    if [ ! -d ~/.delete/${bak_date} ]
    then
        mkdir ~/.delete/${bak_date}
    fi
}

toBackup()
{
    checkDelDir
    for thing in $@
    do
        echo $thing | grep '^-' > /dev/null
        if [ ! $? = 0 ]
        then
            mv $thing $HOME/.delete/${bak_date}/${del_time}-$thing
            echo rename $thing to ${del_time}-$thing and mv to ~/.delete/${bak_date}
        fi
    done
}

cleanDelete()
{
    echo 'Clear all backup files?[y/N]'
    read confirm
    [ $confirm = 'y' ] || [ $confirm = 'Y' ]  && /bin/rm -rf $HOME/.delete/*
}

listDelete()
{
    echo 'ls $HOME/.delete/${bak_date}'
    echo 'Only list what you delete today'
    echo
    ls $HOME/.delete/${bak_date}
}

alias rm=toBackup
alias lsdel=listDelete
alias cleandel=cleanDelete

# }}

发表评论

电子邮件地址不会被公开。 必填项已用*标注