Linux中的history命令
history是用来显示命令历史的命令。
1
2
3
4
5
6
7
root@aml:~# history
    1  which git
    2  cd /
    3  ls -l
    4  ifconfig
    5  alias
    ...
- 默认记忆 1000 个历史,这些命令保存在家目录的
~/.bash_history里。 history #列出最近的#条命令,例如history 5history -c会将当前 shell 里的命令历史记录。history -d #会删除第#条历史命令,例如history -d 10删除第 10 条历史。history -w会将当前 shell 里的命令历史写进.bash_history,注销后也会自动写入。!#用来执行第#条命令,例如!5就是执行第 5 条历史命令。!-#用来执行倒数第#条命令,例如!-2就是执行倒数第 2 条命令。!command用来执行最近历史里的以command开头的命令,例如!ls会执行最近的ls命令包括参数。!!用来执行上一条历史命令。!$可以取到上一条命令的参数,假如刚刚执行完vi hello.txt再cat !$,等同于cat hello.txt。echo "export $HISTSIZE=500" >> /etc/profile修改当前 shell 缓存的历史上限。echo "export $HISTFILE=~/.history" >> /etc/profile修改保存历史的文件名字。echo "export $HISTFILESIZE=1000" >> /etc/profile修改最大保存历史命令上限。echo "export HISTTIMEFORMAT='%F %T" >> /etc/profile修改历史文件的内容格式,带上时间戳。- 以上修改需要 
source /etc/profile才能生效,不过更建议修改个人目录下的.bash_profile。 
 This post is licensed under  CC BY 4.0  by the author.