Reputation: 529
I need to use a command and or script that uninstalls the last recently installed application deb . I can't use apt-get in this case but rather dpkg --purge or similar, something like dpkg --remove (last recently installed application) but without providing the name of the application.
thanks
Upvotes: 2
Views: 5760
Reputation: 3145
ls -tl /var/lib/dpkg/info/*.list | head -n 1 | awk '{print $8}' | xargs -n1 basename | sed -e "s/.list//"
ls -tl /var/lib/dpkg/info/*.list : gives you the list of package sorted by date
head -n 1 : gives you the first item
awk '{print $8}' : gives you the fullpath filename
xargs -n1 basename : gives the filename , like curl.list
sed -e "s/.list//" | gives you the package name
Upvotes: 1
Reputation: 16528
Finding the last installed package is relatively simple. It's the newest entry in /var/lib/pkg/info.
However, uninstalling that will not necessarily restore the system to its prior state.
Installing a package will also install all of its dependencies. So, to really undo the install you also need to undo those dependencies. You can see that 'libfoo' was updated around the same time as 'appbar'. However, the info files will not tell if the previous state was no 'libfoo', or just an older version of 'libfoo'.
Upvotes: 0