我注意到在apt list中有很多状态为"residual-config"的软件包,但在删除它们之前,我想确保不会删除任何重要信息,我该如何显示将被删除的文件列表?
for i in $(dpkg --list | awk '{if ($1 == "rc") {print $2}}'); do if [ ! -f /var/lib/dpkg/info/$i.postrm ]; then sudo apt-get purge -y $i; fi; done
- Martin Bonner supports Monicapostrm
脚本(因此不执行任何操作)的包(我刚刚删除了20个左右这样的包)。 - Martin Bonner supports Monicaapt-cache show '?config-files' | grep -oP '^Package: \K(.*)$' | uniq | xargs -I '0' dpkg-query -W --showformat "\${binary:Package}:\n\${db-fsys:Files}" '0'
示例输出:
postgresql-13:
postgresql-common:
/etc
/etc/init.d
/etc/init.d/postgresql
/etc/logrotate.d
/etc/logrotate.d/postgresql-common
/etc/postgresql
/etc/sysctl.d
/etc/sysctl.d/30-postgresql-shm.conf
/var
/var/lib
/var/lib/postgresql
/var/log
/var/log/postgresql
Explanation:
apt-cache show '?config-files'
: 按照 apt search patterns 显示过时的配置文件。grep -oP '^Package: \K(.*)$' | uniq
: 过滤软件包名称并从前一步骤中去除重复的输出。xargs -I '0' dpkg-query -W --showformat "\${binary:Package}:\n\${db-fsys:Files}" '0'
: 将软件包名称传递给 dpkg-query
并打印 Package
字段(软件包名称)和一个特殊的 db-fsys:Files
字段,其中列出了当前在您系统上安装的该软件包的所有文件。注意:您也可以使用以下命令清理系统中的所有剩余配置文件:
sudo apt purge '?config-files'
db-fsys:Files
中提到了postrm脚本中不存在的文件。例如,我检查了tor
软件包,postrm中包含rm -f "/etc/apparmor.d/disable/system_tor"
,而在dpkg-query -W --showformat "\${binary:Package}:\n\${db-fsys:Files}" tor
中却没有。这是否符合预期? - int_uaapt purge '?config-files'
之前,请务必备份所有内容;它抹掉了我的Maria数据库! - Lamp'?data-files'
或者其他用于将这类东西与配置文件分开处理的方法。我会在答案中加上一个警告。 - voodooattack--dry-run
并没有真正帮助。它只列出了软件包,而没有列出文件。同时,大多数软件包在该列表中会显示 /etc
,但(希望)不会删除它。 - undefined#!/bin/bash
set -eo pipefail
apt-cache show '?config-files' | grep -oP '^Package: \K(.*)$' | uniq | while read -r pkg; do
dpkg-query -W --showformat "\${binary:Package}:\n\${db-fsys:Files}" "${pkg}"
if [[ -e /var/lib/dpkg/info/${pkg}.postrm ]]; then
echo " postrm:"
sed 's/^/ /' /var/lib/dpkg/info/${pkg}.postrm
fi
done
$ apt-list-residual-files.sh
libatk-adaptor:amd64:
/etc
/etc/X11
/etc/X11/Xsession.d
/etc/X11/Xsession.d/90atk-adaptor
/etc/environment.d
/etc/environment.d/90atk-adaptor.conf
xbrlapi:
/etc
/etc/X11
/etc/X11/Xsession.d
/etc/X11/Xsession.d/90xbrlapi
postrm:
#!/bin/sh
set -e
# Automatically added by dh_installdeb/13.11.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/X11/Xsession.d/60xbrlapi 6.1\+dfsg-2\~ xbrlapi -- "$@"
# End automatically added section
apt-get purge
。 - int_uaapt list
命令时,我只会得到一个类似这样的软件包列表:package_name/version/(amd64|i386|all)。没有提及状态信息。如何通过apt list
命令获取状态信息呢?我可以使用dpkg --list | grep ^rc
命令来获得相同的信息。 - DK Boseapt 1.0.10.2ubuntu1
版本中,这将显示所有带有状态的软件包:apt list | grep "\[.*\]"
。 - int_ua