Pur*_*ket 5 bash shell history built-in
我想做类似的事情
history 2960-2966
Run Code Online (Sandbox Code Playgroud)
具有这种输出的期望:
2960 2013-12-09 20:59:35 bundle update
2961 2013-12-09 21:00:08 git st
2962 2013-12-09 21:00:12 git add .
2963 2013-12-09 21:01:19 git st
2964 2013-12-09 21:01:43 git log
2965 2013-12-09 21:02:45 git st
2966 2013-12-09 21:02:57 git reset HEAD Gemfile.lock
Run Code Online (Sandbox Code Playgroud)
在bash shell中有可能吗?
更新:我的问题是关于查看这七个历史记录行,而不是日期本身;碰巧我HISTTIMEFORMAT在.bash_profile中有一条指令来提供日期和时间戳。如果要删除它,那么我希望history 2960-2966或其他一些东西来生成此输出:
2960 bundle update
2961 git st
2962 git add .
2963 git st
2964 git log
2965 git st
2966 git reset HEAD Gemfile.lock
Run Code Online (Sandbox Code Playgroud)
我希望显示所需的历史记录行,最好使用在.bash_profile中指定的任何自定义设置。
我为什么要这个?一个非常简单的用例是:我做类似的事情来history | grep 'bundle update'获得一个不错的结果,然后想要查看该点的一些历史记录以及更远的几行内容,或者是将该点括号括起来的历史记录。
你可以使用sed. 说:
history | sed -n '2960,2966p'
Run Code Online (Sandbox Code Playgroud)
从命令的输出中打印行号 2960 到 2966 history。
引用help history:
If the $HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.
Run Code Online (Sandbox Code Playgroud)
您可以设置格式以获取所需格式的时间戳:
export HISTTIMEFORMAT="%F %T "
Run Code Online (Sandbox Code Playgroud)
由于history默认情况下仅在会话关闭时写入文件,因此您需要说:
history -w
Run Code Online (Sandbox Code Playgroud)
为了更新当前会话中的历史文件。
| 归档时间: |
|
| 查看次数: |
384 次 |
| 最近记录: |