系统相关
首页 > 系统相关> > linux 防掉坑神器之 safe_rm

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" }

  

标签:bin,return,safe,rm,TRASH,防掉,DIR
来源: https://www.cnblogs.com/lickyzh/p/14985295.html