有人知道在使用aptitude(或apt-get)时,是否有一种简单的方法可以按日期排序找到已安装的软件包列表吗?
我安装了一堆软件包来尝试新东西,但结果不理想。我想删除所有这些软件包,以释放一些磁盘空间。
我尝试过只查看下载的.deb文件列表,但这似乎是一种相对繁琐的方式(尽管它确实有效)。
我安装了一堆软件包来尝试新东西,但结果不理想。我想删除所有这些软件包,以释放一些磁盘空间。
我尝试过只查看下载的.deb文件列表,但这似乎是一种相对繁琐的方式(尽管它确实有效)。
/var/lib/dpkg/info
的文件的时间戳来找到安装日期。*.list
文件上的时间戳,因为其他文件都带有软件包日期。 - Daveaptitude
会将日志写入到/var/log/aptitude
文件中。它生成的输出如下所示:===============================================================================
Aptitude 0.8.12: log report
Sun, Oct 1 2021 23:59:59 +1300
IMPORTANT: this log only lists intended actions; actions which fail
due to dpkg problems may not be completed.
Will install 6 packages, and remove 0 packages.
31.3 MB of disk space will be used
========================================
[UPGRADE] libc-dev-bin:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6:i386 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-dbg:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-dev:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
[UPGRADE] libc6-i386:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2
========================================
Log complete.
===============================================================================
Option:Aptitude::Log
Default:/var/log/aptitude
Description: If this is set to a nonempty string, aptitude will log the package
installations, removals, and upgrades that it performs. If the value of
Aptitude::Log begins with a pipe character (ie, ``|''), the remainder of its
value is used as the name of a command into which the log will be piped: for
instance, |mail -s 'Aptitude install run' root will cause the log to be emailed
to root. To log to multiple files or commands, you may set this option to a list
of log targets.
grep " install" /var/log/dpkg.log*
cd
命令的目的是在此目录中使用ls
命令来检查可用的dpkg.log文件。但更好的解决方案是运行ls /var/log | grep 'dpkg.log'
以列出日志文件。对于造成的混乱,我表示抱歉。 - jmarcelicat | cat
是一种可以做的事情。但为什么不在一个命令中同时使用cat两个文件呢?(或者更好的是:就像@MarcVanDaele说的那样去做。) - mwfearnleyfunction apt-history(){
case "$1" in
install)
cat /var/log/dpkg.log | grep 'install '
;;
upgrade|remove)
cat /var/log/dpkg.log | grep $1
;;
rollback)
cat /var/log/dpkg.log | grep upgrade | \
grep "$2" -A10000000 | \
grep "$3" -B10000000 | \
awk '{print $4"="$5}'
;;
*)
cat /var/log/dpkg.log
;;
esac
}
编辑
我在Ubuntu 8.10服务器上尝试了这个脚本,效果非常好。 你能提供一些信息,说明你是如何解决你的问题的吗?
使用 dpkg 日志
locate dpkg.log | xargs cat {} | grep " install "
或者如果你没有 locate
find /var/log/ -name 'dpkg.log' | xargs cat {} | grep " install "
使用 sort
来确保按时间顺序排序
locate dpkg.log | xargs cat {} | grep " install " | sort
使用 tac
(反向的 cat
)*,head 例如获取最新的4个条目
locate dpkg.log | xargs cat {} | grep " install " | sort | tac | head -n4
2014-10-08 18:56:12 install xorg-server-source:all <none> 2:1.16.1-1
2014-10-08 18:49:34 install libelementary-data:all <none> 0.7.0.55225-1
2014-10-08 18:46:57 install e17:i386 <none> 0.17.6-1
2014-10-08 18:46:56 install libedje-bin:i386 <none> 1.8.6-2.1+b1
tac
+ head
而不是 tail
? - Zannapkginstall.sh
脚本可以完成这个任务。请按照官方文档中的说明进行操作。简单来说,从上面的链接下载脚本,确保它可执行,然后运行以下命令:
~/pkginstalls.sh
pkginstalls.txt
的文件,其中包含按日期排序的所有已安装软件包。#!/bin/bash
#pkginstalls.sh
#creates text file with a list of all packages installed by date
#first append all info from archived logs
i=2
mycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)
nlogs=$(( $mycount + 1 ))
while [ $i -le $nlogs ]
do
if [ -e /var/log/dpkg.log.$i.gz ]; then
zcat /var/log/dpkg.log.$i.gz | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))
done
#next append all info from unarchived logs
i=1
nulogs=$(ls -l /var/log/dpkg.log.* | wc -l)
nulogs=$(( $nulogs - $nlogs + 1 ))
while [ $i -le $nulogs ]
do
if [ -e /var/log/dpkg.log.$i ]; then
cat /var/log/dpkg.log.$i | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))
done
#next append current log
cat /var/log/dpkg.log | grep "\ install\ " >> $HOME/pkgtmp.txt
#sort text file by date
sort -n $HOME/pkgtmp.txt > $HOME/pkginstalls.txt
rm $HOME/pkgtmp.txt
exit 0