CentOS 显示历史执行过的命令以及用户历史命令缓存文件
2023-09-14 09:02:30 时间
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 2019pts/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 2019-01-05 22:17:21 export HISTTIMEFORMAT="%F %T " 1025 2019-01-05 22:17:24 history 1026 2019-01-05 22:19:00 export 1027 2019-01-05 22:19:09 export | grep HIST 1028 2019-01-05 22:19:41 history | less 1029 2019-01-05 22:19:53 history
相关文章
- CentOS 6.4 图文安装教程(有些设置大部分教程没出现过)
- CentOS下Qt安装
- CENTOS 下安装APK反编译工具 APKTOOL
- 用POSTFIX,DOVECOT,OPENWEBMAIL集成在CENTOS上
- OA项目迁移到CentOS
- 如何使红帽系统用centos的yum源?
- Centos 6.4部署DNS服务器
- 两台centos之间传送文件
- centos平台scp通过密钥远程复制文件(免密登录)
- CentOS完美搭建Redis3.0集群并附测试
- [转]CENTOS 使用RSYNC+INOTIFY实现文件实时自动同步
- CentOS 7 安装 中文字体
- docker从零开始(一)centos获取安装docker-ce
- 锁定文件失败,打不开磁盘“D:biehlcentostaotaotaotao-dubbo-registerCentOS-000001.vmdk”或它所依赖的某个快照磁盘。模块“Disk”启动失败。未能启动虚拟机
- 用CentOS 7自制Vagrant Box文件
- CentOS下通过yum安装svn及配置
- CentOS找不到VMware共享的文件夹