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

0xC*_*22L 88 aptitude apt

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

在特定的软件包奥赫为sambanullmailerlocalepurgelighttpd强迫我与终端交互,即使整个过程,脚本和意思是是非交互式的。

Sav*_*vic 117

您可以使用:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
Run Code Online (Sandbox Code Playgroud)

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

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mypackage1 mypackage2
Run Code Online (Sandbox Code Playgroud)

来源: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";
}
Run Code Online (Sandbox Code Playgroud)

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

  • “我相信这是不言自明的”......继续使用我从未见过任何人用于 apt-get 的选项 (37认同)
  • `-y` 呢? (4认同)
  • 另请参阅:https://linux.die.net/man/1/dpkg 在 `--force` 部分下,它描述了 `confold` 和 `confdef` 选项。也有帮助:来自 https://askubuntu.com/questions/254129/how-to-display-all-apt-get-dpkgoptions-and-there-current-values 的 `apt-config dump` (4认同)
  • “不言自明”……嗯,我发现这个描述非常混乱,尤其是是否组合使用它们。解决问题的是`dpkg(1)`。谢谢@thom_nic。 (3认同)
  • @notbad.jpeg:我相信这句话是针对这些选项的命名。我发现这些名称确实不言自明。当然知道使用它们不是:-D (2认同)