【问题标题】:Search command-line history for lines beginning with "git"在命令行历史记录中搜索以“git”开头的行
【发布时间】:2023-04-01 05:51:01
【问题描述】:

我试过了,但什么也没找到:

history | grep "^git"

这发现太多行:

history | grep "git"

【问题讨论】:

    标签: bash shell history


    【解决方案1】:

    history 命令在实际命令之前显示数字,因此请尝试改用此awk 命令:

    history | awk '$2 == "git"'
    

    或者

    history | awk '$2 ~ /^git/'
    

    您也可以只搜索~/.bash_history,但此文件的内容可能并不总是反映当前的历史记录:

    grep '^git' ~/.bash_history
    

    【讨论】:

    • history | grep "^\d+ git" 也不在这里工作。 history | grep "\d+ git" 很好,但不保证它从一开始就在寻找。我更喜欢下次使用grep '^git' ~/.bash_history
    猜你喜欢
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 2012-01-23
    • 2019-12-01
    相关资源
    最近更新 更多