gpt4 book ai didi

linux - 使用 shell 命令从 yum 命令历史记录中检索补丁名称

转载 作者:太空宇宙 更新时间:2023-11-04 05:34:12 26 4
gpt4 key购买 nike

我正在使用命令来获取补丁列表:

sudo yum --setopt=history_list_view=commands history list all

输出:

ID | Command line             | Date and time    | Action(s)      | Altered

13 | remove wget | 2018-10-16 08:56 | Erase | 2
12 | install sssd-1.12.4-47.e | 2018-10-16 03:09 | Update | 4 ss
11 | install unzip-6.0-2.el6_ | 2018-10-15 09:27 | Update | 1
10 | install sqlite-3.6.20-1. | 2018-10-15 09:26 | Update | 1
9 | install pam-1.1.1-20.el6 | 2018-10-15 09:22 | Update | 1
8 | install libxml2-python-2 | 2018-10-15 09:20 | Update | 2
7 | install curl.x86_64 | 2018-10-15 08:56 | Update | 2
6 | install dhclient.x86_64 | 2018-10-15 08:55 | Update | 2
5 | install openssh.x86_64 | 2018-10-15 08:50 | Update | 3
4 | install samba-winbind-3. | 2018-10-15 04:59 | Update | 4
3 | install zsh-html.x86_64 | 2018-10-12 06:57 | Install | 1
2 | install samba | 2017-01-05 03:17 | I, U | 5
1 | install wget | 2017-01-05 03:08 | Update | 1

如何处理这个问题并仅从命令行列获取补丁名称?

最佳答案

您可以使用 awk 获取仅包名称这样:

sudo yum --setopt=history_list_view=commands history list all | awk -F '|' 'NR>2{print $2}' | awk 'NF{print $2}'

第一个 awk 表达式按 | 字符分割每个字符串,并给出第二列(除了描述表标题的前两行 NR>2 )。第二个 awk 表达式按空格字符分割第二列并为您提供包名称,同时过滤空行 ( more info about NF in awk )。

输出如下:

curl.x86_64
dhclient.x86_64
openssh.x86_64
zsh-html.x86_64
samba
wget

如果您需要一些过滤,例如通过Action字段,首先需要额外的grep

关于linux - 使用 shell 命令从 yum 命令历史记录中检索补丁名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52836483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com