Skip to content Skip to main navigation Skip to footer

Linux下查看yum命令历史记录的方法

linux_inner如何来查看yum在运行后的历史信息呢?比如安装,删除,更新包的过程记录信息。如何使用yum命令重新安装包呢?如何使用yum命令撤销上次的安装呢?
Yum 命令在Centos/Redhat 6.x+之后提供了一个新的选项:history. 可以通过该选项查看到yum命令的处理过程,回滚,撤销,重新执行历史操作。
Yum命令在3.2以上的版本或者是Centos/RHEL 6.x 提供了history选项,可以通过下面的命令来查看yum的版本号:

#yum info yum

yum history 命令形式如下:

yum history
yum history command
yum history [选项] #选项包括: info|list|packages-list|summary|addon-info|redo|undo|rollback|new

下面举几个例子:
1.显示yum 历史

[root@devops ~]# yum history list
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
2 | root <root> | 2013-12-12 05:34 | I, U | 15
1 | System <unset> | 2013-12-12 05:03 | Install | 332
history list

2.查看所有的处理过程

# yum history list all

查看其中的某个或某个范围的处理过程

#yum history list 1
#yum history list 1..5
[root@devops ~]# yum history list 2
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
2 | root <root> | 2013-12-12 05:34 | I, U | 15
history list

3.查看某个包的yum处理过程,比如firefox

[root@devops ~]# yum history list firefox
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
2 | root <root> | 2013-12-12 05:34 | I, U | 15
history list

还可以通过yum history package-list 查看firefox包的完整包列表信息

root@devops ~]# yum history package-list firefox
Loaded plugins: fastestmirror
ID | Action(s) | Package
-------------------------------------------------------------------------------
2 | Install | firefox-17.0.10-1.el6.centos.x86_64
history package-list

基于上面的包列表中的ID,可以查看那次安装的firefox包的完整处理信息:

[root@devops ~]# yum history info 2
Loaded plugins: fastestmirror
Transaction ID : 2
Begin time : Thu Dec 12 05:34:00 2013
Begin rpmdb : 332:0f20e18208bd2e665c18360a74c87da7278db75a
End time : 05:34:19 2013 (19 seconds)
End rpmdb : 340:a77df63b3e7e6db32a8700a8eb627c71f67d8eae
User : root <root>
Return-Code : Success
Command Line : install firefox
Transaction performed with:
Installed rpm-4.8.0-27.el6.x86_64 @anaconda-CentOS-201207061011.x86_64/6.3
Installed yum-3.2.29-30.el6.centos.noarch @anaconda-CentOS-201207061011.x86_64/6.3
Installed yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201207061011.x86_64/6.3
Packages Altered:
Dep-Install centos-indexhtml-6-1.el6.centos.noarch @base
Install firefox-17.0.10-1.el6.centos.x86_64 @base
Dep-Install hunspell-1.2.8-16.el6.x86_64 @base
Dep-Install liberation-fonts-common-1.05.1.20090721-5.el6.noarch @base
Dep-Install liberation-sans-fonts-1.05.1.20090721-5.el6.noarch @base
...

4.撤销某一次的yum处理过程
我们先用yum把firefox包卸载,然后再撤销卸载,回复正常使用

[root@devops ~]# yum erase firefox
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
...

现在我们来撤销上面的卸载处理,使用下面的命令:
首先查看下卸载操作的ID号

[root@devops ~]# yum history package-list firefox
Loaded plugins: fastestmirror
ID | Action(s) | Package
-------------------------------------------------------------------------------
3 | Erase | firefox-17.0.10-1.el6.centos.x86_64
2 | Install | firefox-17.0.10-1.el6.centos.x86_64
history package-list

从上面的输出我们可以看到卸载操作的ID是3,下面执行撤销操作

# yum history undo 3

5.重新执行某次yum处理过程
输入下面的命令:

#yum history redo id
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.