GithubHelp home page GithubHelp logo

apt-history's Introduction

apt-history

Explore the APT history

Installing (globally)

sudo npm -g i https://github.com/rolfen/apt-history.git

Or, alternatively:

git clone https://github.com/rolfen/apt-history.git
sudo npm -g i ./apt-history

To uninstall:

sudo npm -g r apt-history

Using

apt-history 

By default, it reads last 10 "entries"/"operations" (this number can be changed with --limit) and list commands. The entries are numbered following their sequence in the APT log, zero based. The latest one is at the bottom.

To read 5 entries starting from #40 one in history.log

apt-history --from 40 --limit 5

You can also list packages removed packages, for example

apt-history Remove

Examine operation #4 in the history log

apt-history 4

Get property "Purge" of the operation
This would be the list of packages purged by the command

apt-history 4 Purge

Get packages installed during this operation. --as-apt-argument returns a space-separated list of package names.

apt-history 4 Install --as-apt-arguments

By default, apt-history looks for the APT log at /var/log/apt/history.log.

-s or --stdin allows you to pipe the APT log instead.

cat /var/log/apt/history.log |apt-history -s

You can also specify the location of the log file

apt-history --input /var/log/apt/history.log

Rolling back an apt-get install

The following will attempt to uninstall all packages installed by command #4 (including installed suggested and recommended packages)

sudo dpkg -r `apt-history 4 Install --as-apt-arguments`

Here we use dpkg -r instead of apt-get remove. That is because apt-get remove will automatically remove any dependant package. For example is you do apt-get remove evolution it will automatically remove the whole Gnome desktop package because it depends on evolution.

dpkg will not do such a thing. Faced with this same problem, dpkg will just fail instead of automatically uninstalling dependant packages. In the case where it fails, you can add --force-depends to the dpkg command to tell it to ignore dependency problems.

Ignoring dependency problems with --force-depends can create broken packages (it will print a warning to tell you), in which case you should run apt-get --fix-broken install afterwards.

Notes

Shell tricks

You can also extract useful information using piping and standards shell tools. For example:

cat /var/log/apt/history.log| grep Commandline|nl -v 0|tail 

is similar to:

apt-history 

Misc

I have noticed that the output format of apt-cache show and of cat /var/log/apt/history.log are similar, maybe we can reuse code to parsing code.

Relevant links

apt-history's People

Contributors

rolfen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apt-history's Issues

Negative addresses

Invalid addresses are returned when history.log contains less than 10 entries.

$ cat /var/log/apt/history.log|node ~/apt-history/index.js
-6 apt-get -y install vim
-5 apt-get -y install libreoffice
-4 apt-get -y install tesseract-ocr
-3 apt-get -y install libpoppler-qt4*
$ cat /var/log/apt/history.log|node ~/apt-history/index.js -3
undefined

Argument value `0` is interpreted as `false`

0 as argument value is interpreted as false

Specifically:

cat test/stdin/history_sample.log |./index.js --from 0 --limit 1

Should print:

0  /usr/bin/first-unattended-upgrade

But instead, --from is totally ignored.

Indexes are not guaranteed to be unique

Normal use scenario for apt-history, is that you would you run it once to get a list of transaction, then you run it again to get a detail about a transaction, using an index number from the previously obtained list.

In theory, logrotate could switch out history.log between two invocations, in which case the ID number will be referring to something else.

Some possible solutions:

  • Re-think indexes. Maybe use timestamps instead, for example.
  • Add persistent storage to the script and keep track of the timestamps on history.log, so that a log rotation is detected

In practice, if the log gets rotated between invocations it will most likely result in running apt-history on an empty log which would just cause confusion.

Show fixed number or results

It would be nice to always show the same number of lines for list results.
Right now the number of lines varies, because by default the script parses 10 records, then shows only the relevant records in the output so the number of lines shown can be anywhere from 0 to 10.

Improvement: Automatically find apt log

It is a bit tedious to type cat /var/log/apt/history.log.

Passing the log through stdin is reliable.

However it would be nice to have it implied and automatically loaded by default, so that we do not need to type this every time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.