Specific Zypper command / History

Hi happy people!

I am looking for a specific command in the terminal.

a **history zypper list **command in some sort of sense

when uninstalling something via zypper rm -u “younameit”
It erases all dependencies as well.

just out of curiosity…

In case I forgot how many packages(as dependencies) were installed at that time,
or the suggested dependencies seem very odd…
is there a command for zypper to list what was installed back in time?

I looked into the logs in /var/log/zypper/history and var/log/zypper.log
but I didn´t hit paydirt

1 Like

There is zypper-log command (which is recommended by zypper and so should normally be installed) which parses /var/log/zypper.log* and shows command history.

Add the following alias to your ~/.bashrc file:


alias zypp-hist='sudo cut -d "|" -f 1-4 -s --output-delimiter " | " /var/log/zypp/history | grep -v " radd "'

Then reload your .bashrc file with:


~> . ~/.bashrc

Anytime you open a terminal window, .bashrc is reloaded, so it will always be available, even from a virtual terminal (ctrl-alt F1-F6).

Then you can do things like:


Show the last 10 actions.

gene@Mobile-PC:~> zypp-hist | tail
2021-11-23 08:18:56 | install | libvlccore9 | 3.0.16-4.34
2021-11-23 08:18:56 | install | libavdevice58_13 | 4.4.1-4.9
2021-11-23 08:18:56 | install | libvlc5 | 3.0.16-4.34
2021-11-23 08:18:56 | install | ffmpeg-4 | 4.4.1-4.9
2021-11-23 08:18:58 | install | vlc-noX | 3.0.16-4.34
2021-11-23 08:18:58 | install | vlc-qt | 3.0.16-4.34
2021-11-23 08:18:59 | install | vlc | 3.0.16-4.34
2021-11-23 08:18:59 | install | vlc-codecs | 3.0.16-4.34
2021-11-23 08:19:00 | install | vlc-codec-gstreamer | 3.0.16-4.34
2021-11-23 08:19:00 | install | vlc-vdpau | 3.0.16-4.34


Show the transaction that occurred at a certain date, and time if desired.

> zypp-hist | grep '^2021-11-23 08:'
2021-11-23 08:18:53 | command | root@Mobile-PC | 'zypper' 'dup'
2021-11-23 08:18:54 | install | libavutil56_70 | 4.4.1-4.9
2021-11-23 08:18:54 | install | libxine2 | 1.2.11-166.37
2021-11-23 08:18:54 | install | libpostproc55_9 | 4.4.1-4.9
2021-11-23 08:18:54 | install | libswresample3_9 | 4.4.1-4.9
2021-11-23 08:18:55 | install | libavresample4_0 | 4.4.1-4.9
2021-11-23 08:18:55 | install | libswscale5_9 | 4.4.1-4.9
2021-11-23 08:18:55 | install | libxine2-pulse | 1.2.11-166.37
2021-11-23 08:18:55 | install | libavcodec58_134 | 4.4.1-4.9
2021-11-23 08:18:55 | install | libavformat58_76 | 4.4.1-4.9
2021-11-23 08:18:55 | install | libavfilter7_110 | 4.4.1-4.9
2021-11-23 08:18:56 | install | libxine2-codecs | 1.2.11-166.37
2021-11-23 08:18:56 | install | libvlccore9 | 3.0.16-4.34
2021-11-23 08:18:56 | install | libavdevice58_13 | 4.4.1-4.9
2021-11-23 08:18:56 | install | libvlc5 | 3.0.16-4.34
2021-11-23 08:18:56 | install | ffmpeg-4 | 4.4.1-4.9
2021-11-23 08:18:58 | install | vlc-noX | 3.0.16-4.34
2021-11-23 08:18:58 | install | vlc-qt | 3.0.16-4.34
2021-11-23 08:18:59 | install | vlc | 3.0.16-4.34
2021-11-23 08:18:59 | install | vlc-codecs | 3.0.16-4.34
2021-11-23 08:19:00 | install | vlc-codec-gstreamer | 3.0.16-4.34
2021-11-23 08:19:00 | install | vlc-vdpau | 3.0.16-4.34


List all the packages that were removed at a specific date and time:

> zypp-hist | grep '^2021-03-15 15.* remove'
2021-03-15 15:44:35 | remove  | libXNVCtrl | 435.21-2.14
2021-03-15 15:44:35 | remove  | libXNVCtrl-devel | 435.21-2.14
2021-03-15 15:44:35 | remove  | libXNVCtrl0 | 435.21-2.14
2021-03-15 15:47:01 | remove  | libgpac10 | 1.0.1-1.2
2021-03-15 15:47:01 | remove  | libopenjpeg1 | 1.5.2-6.13
2021-03-15 15:49:49 | remove  | libgpac10 | 1.0.1-1.2
2021-03-15 15:50:09 | remove  | libaudclient2 | 3.5~rc2-2.28


Reinstall all the packages removed on 2021-03-15 at 15.* hour, except for libopenjpeg1 and libgpac10:

sudo zypper install $(zypp-hist | grep '^2021-03-15 15.* remove' | cut -d '|' -f 3 | grep -v libopenjpeg1)

The first grep grabs the transaction list, the cut grabs the package  names, the last grep removes ibopenjpeg1 and libgpac10 from the package  list.

Enjoy,
Gene

1 Like

becaue .bashrc (should) end(s) in

test -s ~/.alias && . ~/.alias || true

I assume the better practice is to add that alias command in the ~/.alias file and not in ~/.bashrc.

I wonder about that. All my openSUSE supplied aliases were in .bashrc when I installed Tumbleweed, so I’ve been putting my own there. Is the preferred location documented somewhere?

Gene

I am not sure where I saw it documented. I know I found out about it sometime somewhere and I have my aliases there already for a long time and to me it seems to be a good way to have them together in a separate and easy to memorize place. Of course your way works also. Maybe personal preference.

But you are right, this is not a very convincing way to present this as “best practice”. :frowning:

looks very nice! Thank you!
how much back in times does it list things?

I am missing the installed and uninstalled packages due to updates though in that list:(

What do you mean with that. Normally a package update does not uninstall anything., neither does it really install something new. It probably just overwrites some of the files of the package.

Yast software management gui has a daily chronological history of all packages installed or deleted since the installation of your system.

Start Yast software management. Go to extras on top menu bar. Click on show history. Daily installs are presented.

This does not show which are installed through commandline zypper vs software management gui; if that is what you’re looking for.

tom kosvic

Take another look at Gene’s suggestion. There’s commands followed by which packages were installed/removed. It won’t tell in particular which package brought a new dependency, zypper nor YaST don’t show this either.

You’re probably talking about Leap. In TW an updated package can add a conflict to an existing package, so it will be removed. And require new dependencies, so they are installed.

I see (I considered that that could be the case in Leap also, but reckoned it as remote). But even then I doubt you can see from those uninstalls and installs that they were due to the update of a particular package (except of course when you only update one package at a time).

But I better leave the thread considering that I am not using TW, that I assume that TW (almost) never does update, but always upgrade. And that I do not really understand the goal of the OP. I just did not understand his statement and in fact asked for clarification.

exactly this answer was what I was looking for.
but in my case even the uninstalled packages via zypper are shown in YAST…
I uninstalled bbswitch yesterday. It shows up there…
maybe I misunderstood the bold written sentence,
what do you mean :)?

exactly the answer I was looking for.
Thank you!
anyway sad…:’(

almost forgot to thank everybody for participating in this thread!

special thanks to Gene for the little script/alias!

@Gene_S

fantastic post of you! Thanks a lot!

I wonder,
there is no option by any chance for “doing” your commands
without having inserted alias to the ~/.bashrc file?
So in other words as a “direct” command in terminal?

Of course you do not need to create that alias. When you want to type that long, long command every time you need it, feel free to do so.

And as the zypper command and YaST > Software > <several menu items>, are both user interfaces to the libzypp library, you can mix working with zypper and YaST > Software and the zypper database and logs will have all actions regardless of what interface you used.

I’ve been using [SuSE] openSuSE since 200? on all my primary systems and have never had a dot alias file that I can recall and is not on my current 15.4 installations, for either norm users or root. : (

@Gene_S, your ‘zypp-hist’ alias is Very nice. Thanks.