Linux 生产环境代替rm脚本

#!/bin/bash
#
# Replace the rm command to prevent misuse
# name: alenx
#
# crontab : 0 0 * * 2,4,6 /bin/rm -rf $(find /* -name .RecycleBin)/* > /dev/null 2>&1
# vi /etc/profile
# alias rm='/bin/bash /usr/local/bin/delete.sh'
# source /etc/profile

current_dir=$(pwd)

if [ ! -d ~/.RecycleBin ]; then
        mkdir ~/.RecycleBin
fi

if [ $# -eq 0 ];then
    echo "Usage: delete file1 [file2 file3 ...]"
else
    echo "My dear, you are about to delete --- :"
    echo $@
        read -p "Are you sure to delete it(them)? [y/n]:" user_answer
        if [ "${user_answer}" == "y" ] || [ "${user_answer}" == "Y" ]; then
                for file in $@; do
                        if [ ${file:(-1)} == "/" ];then
                            file=${file%?}
                        fi
                        if [ -f "${current_dir}/${file}" ] || [ -d "$current_dir/$file" ]; then
                                current_date=$(date)
                                current_date=${current_date// /_}

                                dest_file="${file}__DelTime:${current_date}"

                                mv "${current_dir}/${file}"  "${current_dir}/${dest_file}"
                                mv "${current_dir}/${dest_file}" ~/.RecycleBin
                        else
                                echo "${file}: No such file or directory, my dear!"
                        fi
                done
        else
                echo "No file or directory removed"
        fi
fi

你可能感兴趣的:(Linux,Linux)