使apt-get(或aptitude)与-y一起运行,但不提示替换配置文件?


71

apt-get -y install <packages ...>在Ubuntu 10.04上运行时,我希望apt-get(或者aptitude如果这样可以更容易)在安装其他依赖项时不提示我(-y据我所知),而不提示我覆盖配置文件,而是假设始终保留现有文件(通常是默认设置)。不幸的是,这--trivial-only似乎是相反的-y,并不影响所显示的提示man

尤其是诸如samba,和之类的软件包,即使整个过程都是经过脚本编写并且旨在实现非交互nullmailer,也迫使我与终端进行了交互。localepurgelighttpd

Answers:


97

您可以使用:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

仅针对特定的软件包,例如mypackage1 mypackage2:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mypackage1 mypackage2

来源:http//raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/

Avoiding the conffile prompt

Every time that dpkg must install a new conffile that you have modified
(and a removed file is only a particular case of a modified file in dpkg’s eyes),
it will stop the upgrade and wait your answer. This can be particularly annoying for
major upgrades. That’s why you can give predefined answers to dpkg with the help
of multiple --force-conf* options:

    --force-confold: do not modify the current configuration file, the new version
is installed with a .dpkg-dist suffix. With this option alone, even configuration
files that you have not modified are left untouched. You need to combine it with
--force-confdef to let dpkg overwrite configuration files that you have not modified.
    --force-confnew: always install the new version of the configuration file, the
current version is kept in a file with the .dpkg-old suffix.
    --force-confdef: ask dpkg to decide alone when it can and prompt otherwise. This
is the default behavior of dpkg and this option is mainly useful in combination with
--force-confold.
    --force-confmiss: ask dpkg to install the configuration file if it’s currently
missing (for example because you have removed the file by mistake).

If you use Apt, you can pass options to dpkg with a command-line like this:

$ apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

You can also make those options permanent by creating /etc/apt/apt.conf.d/local:

Dpkg::Options {
   "--force-confdef";
   "--force-confold";
}

您可以在http://manpages.ubuntu.com/manpages/xenial/en/man1/dpkg.1.html上的dpkg手册中找到更多信息和更多选项,或者man dpkg寻找“ confdef”。


33
“我相信这是不言而喻的” ...继续使用我从未见过有人用于apt-get的选项
notbad.jpeg 2015年

1
@ notbad.jpeg:我相信这是针对这些选项的命名。我发现这些名称确实是不言而喻的。当然不是知道要使用它们:-D
0xC0000022L

3
那又如何-y呢?
JDS

4
另请参见:该部分下的linux.die.net/man/1/dpkg--force,其中描述confoldconfdef选项。也很有帮助:apt-config dumpaskubuntu.com/questions/254129/...
thom_nic

3
“不言自明” ...嗯,我发现描述非常混乱,尤其是是否将它们组合使用。清理事情的是dpkg(1)。谢谢@thom_nic。
Lloeki
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.