如何在 Linux 中使用 dpkg --set-selections 指令

如何在 Linux 中使用 dpkg --set-selections 指令

我一直在運行這些命令:

sudo dpkg --clear-selections
sudo dpkg --set-selections < [Path to packages_list ]>
sudo apt-get autoremove

檔案packages_list看起來像這樣

acpi-support                    install
acpid                       install
adduser                     install
adium-theme-ubuntu              install
adobereader-enu                 install
aisleriot                   install
akonadi-server                  install
alacarte                    install
alsa-base                   install
alsa-utils                  install
anacron                     install

我在使用上面提到的第二個命令時遇到了這些錯誤。

dpkg: --set-selections takes no arguments

Type dpkg --help for help about installing and deinstalling packages [*];
Use `dselect' or `aptitude' for user-friendly package management;
Type dpkg -Dhelp for a list of dpkg debug flag values;
Type dpkg --force-help for a list of forcing options;
Type dpkg-deb --help for help about manipulating *.deb files;
Type dpkg --license for copyright license and lack of warranty (GNU GPL) [*].

有人可以幫幫我嗎..

答案1

無論您從何處複製此內容:

sudo dpkg --set-selections < [Path to packages_list ]>

你破壞了它並誤解了結果。我可以這麼說,因為您已經<>安排了一對額外的括號,如果它們實際上存在於您找到的說明中,則將是不必要的(並且間隔不一致)。

它抱怨它不接受參數,因為它接受標準輸入,您應該<在檔案名稱之前使用標準輸入重定向運算子。而且沒有>任何地方。

答案2

dpkg: --set-selections 不含參數

它不使用參數,但需要標準輸入(stdin)反而。

按照man dpkg

--set-selections使用從標準輸入讀取的文件設定包選擇。該檔案應採用「套件狀態」格式,其中狀態為安裝、保留、解除安裝或清除之一。

因此,對於多重選擇,請使用文件:

dpkg: --set-selections < myfile

對於一個包,您可以使用 with echo,例如

echo "acpid hold" | dpkg: --set-selections

對於多個包,您可以使用 with printf(以 分隔的行\n),例如

echo "alsa-base hold\nalsa-utils\n" | dpkg: --set-selections

也可以看看:

相關內容