当 apt 包被标记为“自动安装”时,是否可以查看哪个包触发了安装?

当 apt 包被标记为“自动安装”时,是否可以查看哪个包触发了安装?

apt列出我不认识的自动安装包时,我有时想知道哪个手动安装的包最初触发了安装。这可能吗?

答案1

这是一个脚本示例,使用 2 个命令扫描所有软件包信息,以识别安装软件包的手动软件包。

apt list -installed

=> provide a list of package and you can see if the package was installed automaticaly

apt-cache rdepends --installed PACKAGE

=> 提供当前安装的依赖于 PACKAGE 的列表

#!/bin/bash
if [ -z "$1" ]
then
    echo help:
    echo  $0    PACKAGE
    echo
    echo find packages that was manual installed that install PACKAGE as a dependency
    echo
    exit 1
fi
ROOT_PKG="$1";
echo "package $ROOT_PKG" ;
FG=$(mktemp);
apt list --installed 2>/dev/null | grep automatic > $FG;
ALREADY_DISPLAY=":"
ALREADY_SCAN=":"
while [ -n "$ROOT_PKG" ];
do
      for P in $ROOT_PKG;
      do
              ROOT_PKG="";
              for RDP in $( apt-cache rdepends --installed $P | sed '0,/^Reverse Depends:/  d;' );
              do
                      RDP=$(echo "$RDP" | sed 's/^|//' ) ;
                      if ( grep -q "^${RDP}/"  $FG );
                      then
                              if ( ! ( echo "$ALREADY_SCAN" | grep -q ":$RDP" ) )
                              then
                                  ROOT_PKG="$ROOT_PKG $RDP";
                                  ALREADY_SCAN="$ALREADY_SCAN:$RDP"
                              fi
                      else
                              if ( ! ( echo "$ALREADY_DISPLAY" | grep -q ":$RDP" ) )
                              then
                                 echo " was needed by $RDP";
                                 ALREADY_DISPLAY="$ALREADY_DISPLAY:$RDP"
                              fi
                      fi;
              done;
      done;
done;

相关内容