屏蔽禁用rm命令

几次发生文件被别人误删的事情,又没有办法切分用户,划分权限,所以决定禁用rm命令,改为mv 到Trash中,该方法支持 参数和删除目录

alias rm="trash"
trash()
{
    echo "rm is not permitted, it is dangerous"
    echo "going to execute :"
    echo ""
    for file in $*
    do
        if [ -f "$file" ] || [ -d "$file" ]; then
            echo "mv $file ~/.Trash/"
        fi
        #if [ -f "$file" ]; then
        #    isFile=true
        #    echo "isFile"
        #fi
        #if [ -d "$file" ]; then
        #    isDir=true
        #    echo "isDir"
        #    #mv $@ ~/.trash/

        #    #file $file
        ##elif [ -d "$file" ]; then
        ##    echo "director"
        #fi
        #echo "mv $file ~/.Trash/"
    done

    echo ""

    for file in $*
    do
        if [ -f "$file" ] || [ -d "$file" ]; then
            #echo mv $file ~/.Trash/
            mv $file ~/.Trash/
            #file $file
        fi
    done
} 

Leave a comment

Your email address will not be published.

*