[20210207]bash history小技巧.txt
--//我经常在tmux下工作,在重新调用history命令缓存存在一些问题,做一个记录.
--//通过例子演示:
--//窗口1:
$ qqqqqqqqqqqqq
--//窗口2:
$ wwwwwwwwwwwww
--//窗口1:
$ eeeeeeeeeeeee
--//窗口2:
$ rrrrrrrrrrrrr
--//这个时候如果在窗口1调用窗口2执行的命令无法实现的,通过ctrl+R.
--//实际上就是两个history缓存无法共享.以前我一般通过copy and paste解决.或者关闭退出窗口2.
--//实际上只要执行history -a追加到histfile文件中.另外的窗口执行history -r就可以实现.
--//窗口2:
$ history -a
--//窗口1:
$ history -a
$ history |tail -20
....
6473 2021-02-07 10:04:57 = wwwwwwwwwwwww
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6474 2021-02-07 10:05:17 = rrrrrrrrrrrrr
6475 2021-02-07 10:10:00 = history -a
6477 2021-02-07 10:02:39 = history -a
6478 2021-02-07 10:03:17 = history
6479 2021-02-07 10:04:50 = qqqqqqqqqqqqq
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6480 2021-02-07 10:05:11 = eeeeeeeeeeeee
6482 2021-02-07 10:10:29 = history
6483 2021-02-07 10:10:39 = history | tail
6484 2021-02-07 10:12:12 = history |tail -20
--//注意前面的时间顺序是乱的.这样在窗口1就可以通过ctrl+r调用窗口2曾经执行过的命令.
--//我也尝试将HISTTIMEFORMAT export HISTTIMEFORMAT="$(tty) %F %T =" ,但是没有用.
--//-a仅仅保存时间信息.没有tty命令的信息.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2756677/ ,如需转载,请注明出处,否则将追究法律责任。