让命令历史永久保存并加时间戳

#!/bin/sh
grep HISTTIMEFORMAT /etc/bashrc || echo 'export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "' >>/etc/bashrc
for U in `grep -v shutdown /etc/passwd|awk -F: '$NF~/sh/&&$NF!~/no/{print $1}'`
do
    UHOME=`cat /etc/passwd|grep "^$U"|cut -d: -f6`
    [ ! -f $UHOME/.bash_history ] && touch $UHOME/.bash_history
    chattr +a $UHOME/.bash_history
done

添加新评论 »