我正在运行 Ubuntu 12.10,如果可能的话,我想获取已安装的给定包的可用配置文件列表。
如果可能的话,我更愿意使用 dpkg 或 apt 来执行此操作,但如果需要/推荐其他工具(例如 aptitude 或 dselect),也没有问题。
答案1
cat
如果我正确理解了你的意图,那么没有必要使用除此以外的任何东西:
cat /var/lib/dpkg/info/<package>.conffiles
应该能满足您的要求。例如对于软件包 zsh:
% cat /var/lib/dpkg/info/zsh.conffiles
/etc/zsh/zlogin
/etc/zsh/zlogout
/etc/zsh/zprofile
/etc/zsh/zshenv
/etc/zsh/zshrc
/etc/zsh/newuser.zshrc.recommended
对于给定软件包没有此类文件的情况 - 软件包维护者应指定某些文件作为配置。如果此操作未正确完成,则应在适当的情况下提交错误报告。
在这种情况下,您有几种选择。
列出 /etc/ 中属于该包的文件:
dpkg -L package | grep '/etc'
获取并检查源包以了解它是如何编译的(这也应该向您显示它的配置文件预期位于何处)。
apt-get source package less package-x.y.z/debian/rules
查找上游项目页面来查找文档。
答案2
例如,让我们测试包apt
以获取配置文件。
了解.conffiles
应该检查什么来查看信息可能很棘手,因此我建议使用它grep
来寻找线索。
locate *.conffiles | grep apt
/var/lib/dpkg/info/apt-config-icons.conffiles
/var/lib/dpkg/info/apt.conffiles
/var/lib/dpkg/info/aptdaemon.conffiles
/var/lib/dpkg/info/apturl-common.conffiles
/var/lib/dpkg/info/libatk-adaptor:amd64.conffiles
如果您对cat
其中任何一个感兴趣的话,可以参考 Marcin 的 Kaminski 的回答。
另一个技巧是阅读手册,例如,man apt
它将引导您进入“另请参阅”部分,您可以从中调用,在这种情况下man apt.conf
您将看到配置文件的位置: 。apt
/etc/apt/apt.conf
但是,配置文件/etc/apt/apt.conf
可能根本不存在。在搜索配置文件时请注意这一点。
在 Linux 中,配置文件应该位于/etc/
目录内。您可以使用dpkg-query -L your_package | grep etc
列出/etc/
目录内的所有包文件和目录。
答案3
dpkg -S [package-name] 怎么样?这里没看到有人提到它。
root@homehub:/# dpkg -S nginx
nginx-common: /usr/share/nginx/html
nginx-full: /usr/share/man/man8/nginx.8.gz
libnginx-mod-http-xslt-filter: /usr/share/doc/libnginx-mod-http-xslt-filter/copyright
nginx-common: /etc/logrotate.d/nginx
libnginx-mod-mail: /usr/share/doc/libnginx-mod-mail/changelog.gz
libnginx-mod-http-upstream-fair: /usr/share/doc/libnginx-mod-http-upstream-fair
libnginx-mod-http-auth-pam: /usr/share/doc/libnginx-mod-http-auth-pam/changelog.Debian.gz
libnginx-mod-http-image-filter: /usr/lib/nginx/modules/ngx_http_image_filter_module.so
nginx-common: /etc/nginx/snippets
libnginx-mod-mail: /usr/share/doc/libnginx-mod-mail/copyright
nginx-common: /etc/nginx/snippets/fastcgi-php.conf
libnginx-mod-http-xslt-filter: /usr/share/doc/libnginx-mod-http-xslt-filter/changelog.Debian.gz
nginx-full: /usr/share/doc/nginx-full/copyright
nginx-common: /usr/share/doc/nginx-common
nginx-common: /etc/ufw/applications.d/nginx
libnginx-mod-http-upstream-fair: /usr/share/doc/libnginx-mod-http-upstream-fair/changelog.gz
libnginx-mod-stream: /usr/share/nginx/modules-available/mod-stream.conf
nginx-common: /etc/nginx/sites-enabled
libnginx-mod-http-upstream-fair: /usr/share/doc/libnginx-mod-http-upstream-fair/copyright
libnginx-mod-http-subs-filter: /usr/share/doc/libnginx-mod-http-subs-filter/changelog.gz
libnginx-mod-http-dav-ext: /usr/share/nginx/modules-available/mod-http-dav-ext.conf
nginx-common: /etc/nginx/koi-utf
nginx-common: /etc/nginx/mime.types
nginx-common: /usr/share/vim/addons/syntax/nginx.vim
nginx-common: /usr/share/doc/nginx-common/NEWS.Debian.gz
nginx-common: /usr/share/doc/nginx-common/README.Debian
nginx-full: /usr/share/doc/nginx-full
libnginx-mod-mail: /usr/share/nginx/modules-available/mod-mail.conf
libnginx-mod-http-auth-pam: /usr/share/doc/libnginx-mod-http-auth-pam/changelog.gz
nginx: /usr/share/doc/nginx
nginx-common: /etc/nginx/win-utf
libnginx-mod-http-dav-ext: /usr/share/doc/libnginx-mod-http-dav-ext
....
有时根据文件名结构,通过管道输出到包含“.conf”的 grep 名称可能会很好:
root@homehub:/# dpkg -S nginx |grep ".conf"
nginx-common: /etc/nginx/snippets/fastcgi-php.conf
libnginx-mod-stream: /usr/share/nginx/modules-available/mod-stream.conf
libnginx-mod-http-dav-ext: /usr/share/nginx/modules-available/mod-http-dav-ext.conf
libnginx-mod-mail: /usr/share/nginx/modules-available/mod-mail.conf
libnginx-mod-http-auth-pam: /usr/share/nginx/modules-available/mod-http-auth-pam.conf
nginx-common: /etc/nginx/fastcgi.conf
nginx-common: /etc/init/nginx.conf
nginx-common: /etc/nginx/conf.d
libnginx-mod-http-subs-filter: /usr/share/nginx/modules-available/mod-http-subs-filter.conf
libnginx-mod-http-geoip: /usr/share/nginx/modules-available/mod-http-geoip.conf
libnginx-mod-http-echo: /usr/share/nginx/modules-available/mod-http-echo.conf
libnginx-mod-http-upstream-fair: /usr/share/nginx/modules-available/mod-http-upstream-fair.conf
nginx-common: /etc/init/nginx.conf
libnginx-mod-http-xslt-filter: /usr/share/nginx/modules-available/mod-http-xslt-filter.conf
nginx-common: /etc/nginx/snippets/snakeoil.conf
nginx-common: /etc/nginx/nginx.conf
libnginx-mod-http-image-filter: /usr/share/nginx/modules-available/mod-http-image-filter.conf