一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

Linux|Centos|Ubuntu|系統(tǒng)進(jìn)程|Fedora|注冊表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服務(wù)器之家 - 服務(wù)器系統(tǒng) - Linux - Linux如何在history上添加時(shí)間和用戶等參數(shù)

Linux如何在history上添加時(shí)間和用戶等參數(shù)

2020-07-02 23:58系統(tǒng)之家 Linux

Linux 系統(tǒng)下可以使用 history 命令來查看指令的歷史記錄。為了提高h(yuǎn)istory命令的效率,還可以在history命令加上一些參數(shù),比如時(shí)間、用戶和IP等等參數(shù)。那么如何在history上添加這些參數(shù)呢? 1.設(shè)置顯示時(shí)間和用戶: echo export HISTTIME

Linux系統(tǒng)下可以使用history命令來查看指令的歷史記錄。為了提高h(yuǎn)istory命令的效率,還可以在history命令加上一些參數(shù),比如時(shí)間、用戶和IP等等參數(shù)。那么如何在history上添加這些參數(shù)呢?

Linux如何在history上添加時(shí)間和用戶等參數(shù)

1.設(shè)置顯示時(shí)間和用戶:

echo ‘export HISTTIMEFORMAT=“%F %T `whoami` ”’ 》》 /etc/profile

執(zhí)行source生效:

source /etc/profile

查看結(jié)果:

history

1852 2016-01-11 16:24:52 xubo hs

1853 2016-01-11 16:24:53 xubo ls

1854 2016-01-11 16:24:56 xubo history

1855 2016-01-11 16:25:02 xubo history --help

1856 2016-01-11 16:26:35 xubo vi /etc/profile

1857 2016-01-11 16:27:27 xubo echo ‘export HISTTIMEFORMAT=“%F %T `whoami` ”’ 》》 /etc/profile

1858 2016-01-11 16:27:29 xubo vi /etc/profile

1859 2016-01-11 16:27:42 xubo source /etc/profile

1860 2016-01-11 16:27:46 xubo history

1861 2016-01-11 16:27:59 xubo ls

1862 2016-01-11 16:28:01 xubo history

1863 2016-01-11 16:31:00 xubo clear

1864 2016-01-11 16:31:02 xubo history

2.只看到自己的操作記錄(時(shí)間,用戶,ip名):

USER_IP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

xport HISTTIMEFORMAT=“[%F %T][`whoami`][${USER_IP}] ”

執(zhí)行source生效:

source /etc/profile

查看結(jié)果:

hadoop@Master:~$ history

1002 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] cd 。。/

1003 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] du -h --max-depth=1

1004 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] du -h --max-depth=2

1005 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name pokec-relationships

1006 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name pokec

1007 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name kddcup

1008 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name kddcup*

1009 [2016-01-11 16:47:37][hadoop][host-e-150.ustcsz.edu.cn] sudo find /* -name *kddcup*

3.將history記錄到log:

#export HISTTIMEFORMAT=“%F %T $USER_IP:`whoami` ”

#export HISTTIMEFORMAT=“%F %T $USER_IP:`whoami` ”

USER_IP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

export HISTTIMEFORMAT=“[%F %T][`whoami`][${USER_IP}] ”

#history

LOGIP=`who -u am i 2》/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`

LOG_DIR=/var/log/history

if [ -z $LOGIP ]

then

LOGIP=`hostname`

fi

if [ ! -d $LOG_DIR ]

then

mkdir -p $LOG_DIR

chmod 777 $LOG_DIR

fi

if [ ! -d $LOG_DIR/${LOGNAME} ]

then

mkdir -p $LOG_DIR/${LOGNAME}

chmod 777 $LOG_DIR/${LOGNAME}

fi

export HISTSIZE=4096

LOGTM=`date +“%Y%m%d_%H%M%S”`

export HISTFILE=“$LOG_DIR/${LOGNAME}/${LOGIP}-$LOGTM”

chmod 777 $LOG_DIR/${LOGNAME}/*-* 2》/dev/null

運(yùn)行結(jié)果:

root@xubo:/media/xubo/My Passport/gene_data/1000genomes# ls /var/log/history/root/

host-e-150.ustcsz.edu.cn-20160111_171845 host-e-150.ustcsz.edu.cn-20160111_172719 host-e-213.ustcsz.edu.cn-20160111_202047

root@xubo:/media/xubo/My Passport/gene_data/1000genomes# vi /var/log/history/root/host-e-213.ustcsz.edu.cn-20160111_202047

#1452514808

ls root/

#1452514818

history

#1452514847

source /etc/profile

#1452514848

history

#1452514860

ls root/

#1452514861

ls

#1452514863

cd root/

#1452514864

ls

#1452514866

exit

以上就是Linux如何在history上添加時(shí)間和用戶等參數(shù)的方法了,這樣一來就能讓history查閱命令時(shí)顯示時(shí)間和用戶的這些參數(shù),查找更加精準(zhǔn)。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品国产91久久久久久久a | 欧美人与物videos另类3d | 亚洲精品国产在线观看 | 8mav福利视频| 1769亚洲欧美资源站 | 精品无人区乱码1区2区3区免费 | 性做久久久久久久久老女人 | 99国产小视频 | 欧美日韩精品乱国产 | 日本精品久久久久久久久免费 | 亚洲国产成人在人网站天堂 | 久久精品亚洲国产AV涩情 | 紧身牛仔裤美女被啪啪久久网 | 猫咪免费人成网站在线观看入口 | 黑人巨大初黑人解禁作品 | 亚洲第一综合网站 | 特大黑人娇小亚洲女mp4 | 国产精品污双胞胎在线观看 | 亚洲第一区欧美日韩精品 | 亚洲国产在线播放 | 饭冈加奈子乳喷cead144 | 精品一区二区三区 不卡高清 | 青草悠悠视频在线观看 | 日本 在线播放 | 亚洲精品视频导航 | 成人性生交大片免费看软件 | 国产三级跑 | 四虎国产一区 | 国产福利视频一区二区微拍视频 | 午夜精品免费 | 无码AV精品一区二区三区 | 大胆人gogo888体艺术在线 | 日韩欧美一区黑人vs日本人 | 亚洲精品午夜级久久久久 | 免费黄色片在线观看 | 女子监狱第二季在线观看免费完整版 | 男男playh片在线观看 | 免费一看一级欧美 | 扒开老女人 | 国产高清在线观看 | 欧美性白人顶级hd |