命令历史

    技术2023-08-20  73

    命令历史

    1)检查历史命令的容量。 默认记录1000条,通过全局变量HISTSIZE设置,对所有用户有效:

    [root@svr5 ~]# grep HISTSIZE /etc/profile HISTSIZE=1000

    查看已为当前用户记录的历史命令条数:

    [root@svr5 ~]# history | wc -l 1000

    2)查看历史命令列表。 列出最近执行的10条历史命令:

    [root@svr5 ~]# history | tail 1028 grep 'zhangsan'/etc/passwd 1029cat /etc/redhat-release 1030 usermod -s /bin/tcsh zhangsan 1031 grep 'zhangsan'/etc/passwd 1032 su - zhangsan 1033 echo 1234567| passwd --stdin zhangsan 1034 su - zhangsan 1035 grep HISTSIZE /etc/profile 1036 history | wc -l 1037 history | tail

    3)调用指定的历史命令。 重新执行历史命令列表中的第1028条操作:

    [root@svr5 ~]# !1028 grep 'zhangsan'/etc/passwd zhangsan:x:516:516::/home/zhangsan:/bin/bash

    重新执行最近一次以cat开头(根据实际情况变更)的历史命令操作:

    [root@svr5 ~]# !cat cat /etc/redhat-release Red Hat Enterprise Linux Server… …

    4)清空历史的命令。

    [root@svr5 ~]# history -c //清空自己的历史命令 [root@svr5 ~]# >~/.bash_history //清空记录文件 [root@svr5 ~]# history //再次检查历史命令列表 42>~/.bash_history 43 history
    Processed: 0.009, SQL: 9