Linux基本命令history

1、Linux history记录条数设置

echo "HISTSIZE=1000" >> /etc/profile
. /etc/profile

2、history常用参数

[root@localhost ~]# help history
history: history [-c] [-d 偏移量] [n] 或 history -anrw [文件名] 或 history -ps 参数 [参数...]    
    选项:
      -c	删除所有条目从而清空历史列表。
      -d 偏移量	从指定位置删除历史列表。
    
      -a	将当前绘画的历史行追加到历史文件中
      -n	从历史文件中读取所有未被读取的行
      -r	读取历史文件并将内容追加到历史列表中
    	中
      -w	将当前历史写入到历史文件中
    	并追加到历史列表中
    
      -p	对每一个 ARG 参数展开历史并显示结果
    	而不存储到历史列表中
      -s	以单条记录追加 ARG 到历史列表中

1)显示历史记录,且再次执行其中的一个命令; 

    有三种方式可以再次执行历史记录的命令:

  • 第一个方式是:!数字
  • 第二个方式是: ctrl+r 快捷键从小往上搜索,右方向键确定
  • 第三个方式是: !字符串

 2)打印3行历史记录内容;

  280  vim /etc/profile
  281  cat /etc/profile
  282  history 3

3)将本次缓冲区信息写入到历史文件中; 历史记录是有一个本地用户文件的(~/.bash_history)将文件给删除了,用户重新登入会自动生成一个相同文件出来。

[root@localhost ~]# history -w
[root@localhost ~]# tail -n 3  .bash_history 
history
history 3
history -w

4)将历史文件中的信息读入到当前缓冲区中;

[root@localhost ~]# history -r
[root@localhost ~]# history 
    1  yum grouplist
    2  df -h 
    3  yum grouplist

5)将本次缓冲区信息追加写入到历史记录中;

[root@localhost ~]# history -a 

6)清空本次缓存区;

[root@localhost ~]# history -c
[root@localhost ~]# history
    1  history

7)如果要设置一个用户的密码,但是又担心显示在历史记录会被看到,可以用-d删除;

[root@localhost ~]# useradd user1
[root@localhost ~]# echo "123456" | passwd --stdin user1
更改用户 user1 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# history 2
    4  echo "123456" | passwd --stdin user1
    5  history 2
[root@localhost ~]# history -d 4
[root@localhost ~]# history 3
    4  history 2
    5  history -d 4
    6  history 3

8)因为history默认只能保留1000条历史记录的数量,所以若要增加数量到2000,可以通过修改变量写入到文件里;

[root@localhost ~]# echo $HISTSIZE
1000
[root@localhost ~]# vim .bash_profile 
[root@localhost ~]# tail -n1 .bash_profile 
export HISTSIZE=2000
[root@localhost ~]# source .bash_profile 
[root@localhost ~]# echo $HISTSIZE
2000
[root@localhost ~]# 

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值