加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

两个时间点之间的Bash历史

发布时间:2020-12-15 22:01:56 所属栏目:安全 来源:网络整理
导读:我想做点什么 history 2960-2966 期待这种输出: 2960 2013-12-09 20:59:35 bundle update2961 2013-12-09 21:00:08 git st2962 2013-12-09 21:00:12 git add .2963 2013-12-09 21:01:19 git st2964 2013-12-09 21:01:43 git log2965 2013-12-09 21:02:45 gi
我想做点什么

history 2960-2966

期待这种输出:

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

这可能在bash shell中吗?

更新:我的问题是看到这七个历史行,而不是日期本身;碰巧我在.bash_profile中有一个HISTTIMEFORMAT指令来给出日期和时间戳.如果我要将其删除,那么我希望历史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

我希望显示所需的历史记录行,最好使用我在.bash_profile中指定的任何自定义.

我为什么要这个?一个非常简单的用例是:我做了类似历史的事情grep’bundup’得到一个不错的结果,然后想要从那一点看到一些历史加上几条线,或者可能是包围那一点的历史.

解决方法

你可以使用sed.说:

history | sed -n '2960,2966p'

从history命令的输出中打印行号2960到2966.

引用帮助历史记录:

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.

您可以通过以下方式设置格式以获得所需格式的时间戳:

export HISTTIMEFORMAT="%F %T "

由于历史文件仅在会话结束时默认写入,因此您需要说:

history -w

以便更新当前会话中的历史文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读