基础命令history

history   记录历史命令

   环境变量:

    HISTSIZE: 命令历史记录的条数;

    HISTFILE:  命令历史记录的文件,~/.bash_history;

    HISTFILESIZE: 命令历史文件记录历史的条数;

  常用参数:

    删除一条历史记录:   history -d OFFSET

[root@web1 ~]# history  5
  999  ssh mysql1
 1000  history 
 1001  history  10
 1002  history 
 1003  history  5
[root@web1 ~]# history  -d 1001
[root@web1 ~]# history  5
 1000  history 
 1001  history 
 1002  history  5
 1003  history  -d 1001
 1004  history  5

    清空所有历史记录: history -c 

[root@web1 ~]# history -c 
[root@web1 ~]# history 
    6  history 

    显示历史中最近的#条命令;history #

[root@web1 ~]# history  5
  999  ssh mysql1
 1000  history 
 1001  history  10
 1002  history 
 1003  history  5

    手动追加当前会话缓冲区的命令历史致历史文件中: history -a

[root@web1 ~]# history  5
 1010  more  /root/.bash_history 
 1011  history 
 1012  sadfdasf
 1013  history 
 1014  history  5
[root@web1 ~]# tail -n 5 ~/.bash_history 
vim test.sh
sh test.sh 
mysql_config 
cat /etc/hosts
ssh mysql1
[root@web1 ~]# history -a
[root@web1 ~]# tail -n 5 ~/.bash_history 
sadfdasf
history 
history  5
tail -n 5 ~/.bash_history 
history -a
[root@web1 ~]# 

    调用历史中的命令: 

      !#

      !!: 上一个命令

      !string

      !$:调用上一条命令的最后一个参数

    控制命令历史的记录方式: 修改环境变量

      环境变量:HISTCONTROL

        ignoredups 忽略连续且重复的命令;    

        ignorespace 忽略所有以空白开头的命令;

        ignoreboth:ignoredups,ignorespace

原文地址:https://www.cnblogs.com/lfdblog/p/10659016.html