Linux查看命令行历史命令记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013943420/article/details/82051623

1. 通过history查看历史命令:

[jiaozl@jiaozl 桌面]$ history 
    1  which mpirun
    2  which gfortran
    3  which ifort
    4  which mpif90
    5  ip a s
    6  ifconfig
    7  ip a s
    8  ping baidu.com
    9  service httpd status
   10  systemctl status httpd.service
   11  httpd
   12  whereis httpd
   13  which httpd
   14  yum -y install httpd
   15  su root
   16  vim hello.cpp

前面的数字为历史命令的标号,通过该数字可以执行对应的历史命令

2. 只查看最近5条命令

[jiaozl@jiaozl 桌面]$ history 5
   93  history 5
   94  history
   95  history 5
   96  history
   97  history 5

3. 执行历史命令(通过标号)

【!5】:执行历史编号为5的命令

【!ls】:执行最后一次以“ls”开头的命令

[jiaozl@jiaozl 桌面]$ !h
history 5
   96  history
   97  history 5
   98  !
   99  ls
  100  history 5
[jiaozl@jiaozl 桌面]$ !m
bash: !m: event not found
[jiaozl@jiaozl 桌面]$ !l
ls
a.out  hello.cpp  xxx.txt
[jiaozl@jiaozl 桌面]$ !

猜你喜欢

转载自blog.csdn.net/u013943420/article/details/82051623
今日推荐