Ubuntu记录指令历史(command history),保存到指定文件,方便随时回溯
如题,这里研究了一下ubuntu 的history这个指令,及其相关配置参数。
·
前言
创作开始时间:2021年6月27日17:00:12
如题,这里研究了一下ubuntu 的history这个指令,及其相关配置参数。
1、查看历史指令
history
# 或者
cat ~/.bash_history
都可以。
2、修改history的参数配置(自定义)
终端输入:sudo nano ~/.bashrc
找到其中内容:
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
改成:
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
#HISTCONTROL=ignoreboth
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
#HISTSIZE=1000
#HISTFILESIZE=2000
# 这个意思是不限制大小
HISTSIZE=-1
# 这个指不限制文件大小
HISTFILESIZE=-1
# 这个指保存到指定的文件,即:/home/ubuntu/history.txt
HISTFILE=/home/ubuntu/history.txt
保存,然后source ~/.bashrc
就大功告成!
以后都可以在/home/ubuntu/history.txt查看到历史指令。
小结
以上。
创作结束时间:2021年6月27日17:04:22
参考文献
- Finding an old command in the shell history [duplicate] https://askubuntu.com/questions/897127/finding-an-old-command-in-the-shell-history
更多推荐
已为社区贡献13条内容
所有评论(0)