linux 防掉坑神器之 safe_rm

为了少踩坑,直接上代码

alias rm=safe_rm
export TRASH_DIR={your_path}/.__trash
safe_rm () {
    local d t f s
    [ -z "$PS1" ] && (/bin/rm "$@"; return)
    d="${TRASH_DIR}/`date +%W`"
    t=`date +%F_%H-%M-%S`
    [ -e "$d" ] || mkdir -p "$d" || return
    for f do
        [ -e "$f" ] || continue
        s=`basename "$f"`
        /bin/mv "$f" "$d/${t}_$s" || break
    done
    echo -e "[$? $t `whoami` `pwd`]$@\n" >> "$d/00rmlog.txt"

 

一行:

alias rm=safe_rm export TRASH_DIR={your_path}/.__trash safe_rm () { local d t f s     [ -z "$PS1" ] && (/bin/rm "$@"; return) d="${TRASH_DIR}/`date +%W`" t=`date +%F_%H-%M-%S` [ -e "$d" ] || mkdir -p "$d" || return for f do [ -e "$f" ] || continue s=`basename "$f"`         /bin/mv "$f" "$d/${t}_$s" || break done echo -e "[$? $t `whoami` `pwd`]$@\n" >> "$d/00rmlog.txt" }

  

posted @ 2021-07-08 11:24  大大章鱼  阅读(165)  评论(0编辑  收藏  举报