100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > centos查看历史指令记录_CentOS 显示历史执行过的命令以及用户历史命令缓存文件...

centos查看历史指令记录_CentOS 显示历史执行过的命令以及用户历史命令缓存文件...

时间:2021-07-27 06:15:55

相关推荐

centos查看历史指令记录_CentOS 显示历史执行过的命令以及用户历史命令缓存文件...

1、history命令用于显示历史执行过的命令

执行 history命令能显示出当前用户在本地计算机中执行过的最近 1000 条命令记录。

如果觉得 1000 不够用,还可以自定义/etc/profile 文件中的HISTSIZE 变量值。

在使用 history 命令时,如果使用-c 参数则会清空所有的命令历史记录。

[root@bigdata-senior01 /]# history

36 cat ~/.bash_history

37 history

38 cat ~/.bash_history

39 cat ~/.bash_history | less

40 history

41 ls

42 free -h

43 history

2、使用“!编码数字”的方式来重复执行某一次的命令。

[root@bigdata-senior01 /]# !42

free -h

total used free shared buff/cache available

Mem: 1.8G 156M 1.5G 8.5M 178M 1.5G

Swap: 2.0G 0B 2.0G

3、历史命令会被保存到用户家目录中的.bash_history 文件中。Linux 系统中以点(.)开头的文件均代表隐藏文件,这些文件大多数为系统服务文件,可以用 cat 命令查看其文件内容。

查看自己的home下的用户目录的历史命令记录

“~”波浪线,表示用户家目录

[root@bigdata-senior01 /]# cat ~/.bash_history

“~”波浪线:

[root@bigdata-senior01 ~]# su - es

上一次登录:六 1月 5 21:48:54 CST pts/0 上

[es@bigdata-senior01 ~]$ pwd

/home/es

[es@bigdata-senior01 ~]$ cd /

[es@bigdata-senior01 /]$ ls

bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

[es@bigdata-senior01 /]$ pwd

/

[es@bigdata-senior01 /]$ cd ~

[es@bigdata-senior01 ~]$ pwd

/home/es

4、在histrory记录中加入时间戳

export HISTTIMEFORMAT="%F %T "

[root@bigdata-senior01 ~]# export | grep HIST

declare -x HISTCONTROL="ignoredups"

declare -x HISTSIZE="1000"

declare -x HISTTIMEFORMAT="%F %T "

history显示:

1024 -01-05 22:17:21 export HISTTIMEFORMAT="%F %T "

1025 -01-05 22:17:24 history

1026 -01-05 22:19:00 export

1027 -01-05 22:19:09 export | grep HIST

1028 -01-05 22:19:41 history | less

1029 -01-05 22:19:53 history

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。