Using apt history commands

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
2,712
Reaction score
4,186
Credits
30,502
Debian has introduced functionality to the apt command which enables it to make changes to the system based on the history of changes apt has made. These enhancements are available in apt version 3.2 which is what this post is using in the examples below:
Code:
[~]$ apt list apt
apt/testing,now 3.2.0 amd64 [installed]

Whilst this is a debian testing installation which the following is using, over time the apt enhancements will doubtless be included in the apt packages that are used by the numerous debian derivatives.

Here's a brief table to show the history commands that I know of:
Code:
History command            Function
===============            ========
apt history-list           view history, where an ID is assigned to each operation
apt history-info <ID>      history of operation with the specified ID
apt history-undo <ID>      reverse the operation with the specified ID
apt history-redo <ID>      reverse a "history-undo" operation
apt history-rollback <ID>  undoes all operations that happened after the specified ID

Running apt history-list, to show the past transactions apt executed, has output such as the following, snipped for brevity:
Code:
[~]$ apt history-list
ID   Command line             Date and Time          Action    Changes                

0    install extrepo          2025-04-07  20:22:53   Install   3                      
1    upgrade                  2025-04-07  20:48:18   I,U       183                    
2    autoremove               2025-04-07  20:54:35   Remove    24                     
3    upgrade gstreamer1.0-... 2025-04-07  21:03:06   I,U,R     9                      
4    upgrade qutebrowser      2025-04-07  21:03:55   U,R       2                      
5    install agrep            2025-04-13  16:20:02   Install   1                      
6    upgrade                  2025-04-14  21:12:43   I,U       177                    
7    install finger efinge... 2025-04-16  08:22:03   Install   3                      
8    remove finger efingerd   2025-04-16  13:13:15   Remove    2                      
9    purge finger efingerd    2025-04-16  13:13:32   Purge     1                      
10   install librewolf -y     2025-04-17  15:50:40   Install   1                      
11   upgrade                  2025-04-25  08:29:08   I,U       107                    
12   install cpuinfo          2025-04-27  14:13:48   Install   1                      
13   install flex             2025-04-28  13:18:41   Install   3                      
14   install libear           2025-04-28  13:20:28   Install   7                      
15   install texinfo          2025-04-28  13:22:08   Install   4                      
16   install stress           2025-05-02  20:05:41   Install   1                      
17   upgrade                  2025-05-04  13:38:27   I,U       191                    
18   upgrade                  2025-05-08  21:26:01   I,U       61                     
19   autoremove               2025-05-09  10:46:24   Remove    27                     
20   install dysk             2025-05-11  11:47:44   Install   1                      
<snip>
The history list shows the commands that apt used in past installations of particular packages, past removal and purging of a package, past instances of each upgrade etc., all dated.

To inspect the details of any of those past invocations of apt, one uses the ID number with the history-info option. For example, to see what transaction 19 (autoremove) involved, one can run the following:
Code:
[~]$ apt history-info 19
Transaction ID: 19
Start time: 2025-05-09  10:46:24
End time: 2025-05-09  10:46:32
Requested by:
Command line: apt autoremove
Packages changed:
    Remove libabsl20230802:amd64 (20230802.1-4)
    Remove libcairomm-1.16-1:amd64 (1.18.0-2)
    Remove libdnnl3:amd64 (3.5.3-5)
    Remove libglibmm-2.68-1t64:amd64 (2.84.0-1)
    Remove libgtkmm-4.0-0:amd64 (4.18.0-1)
    Remove libident0:amd64 (0.32-4+b2)
    Remove libopenh264-7:amd64 (2.5.0+dfsg-1)
    Remove libpangomm-2.48-1t64:amd64 (2.56.1-1)
    Remove libpulse-mainloop-glib0:amd64 (17.0+dfsg1-2+b1)
    Remove libqt5qmlworkerscript5:amd64 (5.15.15+dfsg-3)
    Remove libqt5test5t64:amd64 (5.15.15+dfsg-5)
    Remove libqt5webengine-data:amd64 (5.15.18+dfsg-2)
    Remove libqt5webengine5:amd64 (5.15.18+dfsg-2+b1)
    Remove libqt5webenginecore5:amd64 (5.15.18+dfsg-2+b1)
    Remove libsigc++-3.0-0:amd64 (3.6.0-2+b1)
    Remove libxnnpack0:amd64 (0.0~git20240821.87ee0b4-3)
    Remove linux-headers-6.12.20-amd64:amd64 (6.12.20-1)
    Remove linux-headers-6.12.20-common:amd64 (6.12.20-1)
    Remove linux-headers-6.12.21-amd64:amd64 (6.12.21-1)
    Remove linux-headers-6.12.21-common:amd64 (6.12.21-1)
    Remove linux-image-6.12.20-amd64:amd64 (6.12.20-1)
    Remove linux-image-6.12.21-amd64:amd64 (6.12.21-1)
    Remove linux-kbuild-6.12.20:amd64 (6.12.20-1)
    Remove linux-kbuild-6.12.21:amd64 (6.12.21-1)
    Remove pavucontrol:amd64 (6.1-1)
    Remove qml-module-qtquick2:amd64 (5.15.15+dfsg-3)
    Remove qml-module-qtwebengine:amd64 (5.15.18+dfsg-2+b1)
The output shows what the apt command removed.

The command: apt history-undo 19, would reverse that command and reinstall the packages which were removed, and the apt solver, the mechanism for satisfying dependencies, would resolve all of those dependencies. I'm not running that because I don't want that to occur on this machine.

The command: apt history-redo 19, would reverse an undo such as the above command:
apt history-undo 19, which in this case would again remove the packages as executed by apt with the autoremove option. That's a sort of "failsafe" command if a user executes a reversal, but then needs to reverse the reversal, that is, undo what they have done. It's not uncommon for a user to perform an action and then want it reversed, so this command which does that is very welcome.

The command: apt history-rollback <ID> undoes all operations that happened after a specified ID.

In each case of its use, apt resolves dependencies.

Previous to these commands, a user was able to check on history by reference to the /var/log/apt/history.log files and work a bit laboriously if they wished to reverse or manage already executed apt commands.

One might consider the implications the apt history functions may have for other rollback methods such as those used in filesystems like btrfs where snapshots can be used to reverse installations. There may be implications for apps like timeshift and the cloning apps. For example, one might consider a history rollback facility sufficient to satisfy their needs for recovery. However, the apt history commands work at the level of the filesystem over which apt has purview, which is packages. They don't work at the level of a whole system "recollection" which snapshotting and cloning does where everything is captured including configurations and user's modifications. The economy of apt though may be attractive. For those running lesser versions of apt at the moment, I guess it's something to look forward to in a future upgrade :-) .

The current man page for apt on this machine's latest upgrade this morning hasn't as yet included the history commands.
 
Last edited:


Now that (^^^^) is a great Tip, @osprey :)

I myself was unaware of some of those options for querying apt history, and I have been using it for 15 years or more.

It might prove invaluable for some of our Helpers in assisting with Debian-based support threads, so if we get a few more positive reactions (likes), I will pin it to this subforum (may do it any way)

Avagudweegend

Wiz
 
Bash:
apt history-list           view history, where an ID is assigned to each operation
apt history-info <ID>      history of operation with the specified ID
apt history-undo <ID>      reverse the operation with the specified ID
apt history-redo <ID>      reverse a "history-undo" operation
apt history-rollback <ID>  undoes all operations that happened after the specified ID

I don't like how these commands are named, typing the dash is trouble and the option names are too long to type as well.

This should be this instead:
Bash:
apt info
apt undo
apt redo
apt rollback

Don't you agree?
 
Bash:
apt history-list           view history, where an ID is assigned to each operation
apt history-info <ID>      history of operation with the specified ID
apt history-undo <ID>      reverse the operation with the specified ID
apt history-redo <ID>      reverse a "history-undo" operation
apt history-rollback <ID>  undoes all operations that happened after the specified ID

I don't like how these commands are named, typing the dash is trouble and the option names are too long to type as well.

This should be this instead:
Bash:
apt info
apt undo
apt redo
apt rollback

Don't you agree?
I guess these decisions about names for options, and executables for that matter, are at the discretion of the developers, and that they have their reasons for their selections. Users can supply input through communication with them via their emails, various developer lists and forums. One would likely need to be in on the matters at the beginning or early stages of development.

It's not unusual in modern times to have long options and hyphenated ones such as those used in the apt history ones. Systemd has adopted this practice in many of it's commands. For example on the systemctl manpage there's:

list-mounts
list-paths
list-sockets
list-timers
is-active
is-failed
try-restart
reload-or-restart
etc.

These options are somewhat of a description of their function, which is why they are the way they are I guess. They could doubtless be shortened but at the expense of the meaning conveyed by the full hyphenated option.

It's not only options that are hyphenated which makes them much longer. Again, systemd is prominent with this. For example run systemd- and TAB to see lots of long named executables:
Code:
[~]$ systemd-
systemd-ac-power                systemd-detect-virt             systemd-pty-forward
systemd-analyze                 systemd-escape                  systemd-run
systemd-ask-password            systemd-firstboot               systemd-socket-activate
systemd-cat                     systemd-hwdb                    systemd-stdio-bridge
systemd-cgls                    systemd-id128                   systemd-sysext
systemd-cgtop                   systemd-inhibit                 systemd-sysusers
systemd-confext                 systemd-machine-id-setup        systemd-tmpfiles
systemd-creds                   systemd-mount                   systemd-tty-ask-password-agent
systemd-cryptenroll             systemd-mute-console            systemd-umount
systemd-cryptsetup              systemd-notify                  systemd-vpick
systemd-delta                   systemd-path

When one examines executables in the /usr/bin directory, there are hundreds of command names which are longer because of hyphenation which in most cases provides more meaning in the name than a singular expression might:
Code:
[~]$ ls /usr/bin | grep '-' | wc -l
733
On this machine there are 733 hyphenated names of executables. Some names that tend to reveal their function are:
dpkg-buildpackage
distro-info
dpkg-scanpackages
evince-previewer
xdg-screensaver
xdg-user-dir
x-window-manager
etc.

With options, there's often the TAB completion function available, just as there is for executable names themselves, for example with systemctl:
Code:
[~]$ systemctl list-<TAB>
list-automounts    list-jobs          list-paths         list-timers        list-units      
list-dependencies  list-machines      list-sockets       list-unit-files
The TAB function reveals the options. And that works with apt history commands too:
Code:
[~]$ apt history-
history-list      history-info      history-undo      history-redo      history-rollback

Personally I'm not fussed about the length of option or executable names. No need for "Speedy Gonzales" here, which might explain that. There are means for shortening these expressions by the use of aliases and shell functions if one prefers that sort of brevity and it could make for a cleaner looking system.
 
Last edited:
Conceivably, you could generate a series of Aliases, even with shortcut key combos, that would duplicate the relevant longer options, but in my case, I would want to have a cheat sheet beside my rig to refer to until I learned them, and the investment in time to generate same might be daunting.
 
I don't like how these commands are named, typing the dash is trouble and the option names are too long to type as well.

That is how fedora/redhat does it.

Code:
 dnf history list
ID Command line                                                                                                                                                                 Date and time       Action(s) Altered
81 dnf remove xsane                                                                                                                                                             2026-04-21 22:02:55                 2
80 dnf install gscan2pdf                                                                                                                                                        2026-04-21 22:01:37                90
79 dnf install simple-scan                                                                                                                                                      2026-04-21 22:00:04                 1
78 dnf install adwaita-gtk2-theme                                                                                                                                               2026-04-21 21:59:39                 2
77 dnf reinstall xsane                                                                                                                                                          2026-04-21 21:58:46                 2
76 dnf install kernel-6.19.12-200.fc43.x86_64                                                                                                                                   2026-04-21 21:52:05                 4
75 dnf remove kernel*-7.0.0-62.fc45*                                                                                                                                            2026-04-21 21:50:07                 4
74 dnf reinstall xsane                                                                                                                                                          2026-04-21 20:18:18                 2
73 dnf remove fedora-gpu-manager                                                                                                                                                2026-04-21 02:01:37                 1
72 dnf update -y
 


Follow Linux.org

Members online

No members online now.

Top