1.history是Linux系统的一个命令,主要作用是显示执行过的命令,对历史命令记录的管理。
2.Linux系统默认会记录用户所执行过的所有命令,可以使用history命令查阅它们,也可以对其记录进行修改和删除操作。
查看操作系统的版本
[root@jeven ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"[root@jeven ~]# uname -r 
3.10.0-957.el7.x86_64
语法格式: history [参数]常用参数:-a	写入命令记录
-c	清空命令记录
-d	删除指定序号的命令记录
-n	读取命令记录
-r	读取命令记录到缓冲区
-s	将指定的命令添加到缓冲区
-w	将缓冲区信息写入到历史文件
查看所有执行过的命令
[root@jeven ~]# history 10  ls11  history 12  pwd13  tree14  aa15  ls16  history 17  pwd18  history 显示最近的3条历史命令。
[root@jeven ~]# history 318  history 19  history 220  history 3
使用history -c清除历史命令记录
history -c!+历史命令编号,引用历史命令。
[root@jeven ~]# history 10  ls11  history 12  pwd13  tree14  aa15  ls16  history 17  pwd18  history 19  history 220  history 321  history 
[root@jeven ~]# !10
ls
anaconda-ks.cfg  dockerdata  Downloads      initial-setup-ks.cfg  mysql     Public        runc.amd64  Videos
Desktop          Documents   get-docker.sh  Music                 Pictures  rainbonddata  Templates   wiki将历史文件中的信息读入到当前缓冲区中.
[root@jeven ~]# history -r history -whistory -a
[root@jeven ~]# echo  $HISTSIZE
1000
[root@jeven ~]# 查看历史命令记录文件,最大保存1000条,且是上次注销前最近的1000条记录。
[root@jeven ~]# cat ~/.bash_history  |head -n  3
vim docker-compose.yaml 
docker compose up -d
vim docker-compose.yaml 需要在etc/profile修改HISTSIZE的环境变量。
[root@jeven ~]# sed -i 's/^HISTSIZE=1000/HISTSIZE=2000/' /etc/profile
[root@jeven ~]# source /etc/profile   查看修改后的历史命令保留最大调试。
[root@jeven ~]# echo $HISTSIZE
2000