自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在Linux上安裝/卸載一個文件中列出的軟件包?

系統(tǒng) Linux
不要擔(dān)心我們可以幫你擺脫這樣的情況和場景。我們在這篇文章中增加了四種方法來克服困難。

 [[266963]]

在某些情況下,你可能想要將一個服務(wù)器上的軟件包列表安裝到另一個服務(wù)器上。例如,你已經(jīng)在服務(wù)器 A 上安裝了 15 個軟件包并且這些軟件包也需要被安裝到服務(wù)器 B、服務(wù)器 C 上等等。

我們可以手動去安裝這些軟件但是這將花費大量的時間。你可以手動安裝一倆個服務(wù)器,但是試想如果你有大概十個服務(wù)器呢。在這種情況下你無法手動完成工作,那么怎樣才能解決問題呢?

不要擔(dān)心我們可以幫你擺脫這樣的情況和場景。我們在這篇文章中增加了四種方法來克服困難。

我希望這可以幫你解決問題。我已經(jīng)在 Centos7 和 Ubuntu 18.04 上測試了這些命令。

我也希望這可以在其他發(fā)行版上工作。這僅僅需要使用該發(fā)行版的官方包管理器命令替代本文中的包管理器命令就行了。

如果想要 檢查 Linux 系統(tǒng)上已安裝的軟件包列表,請點擊鏈接。

例如,如果你想要在基于 RHEL 系統(tǒng)上創(chuàng)建軟件包列表請使用以下步驟。其他發(fā)行版也一樣。

  1. # rpm -qa --last | head -15 | awk '{print $1}' > /tmp/pack1.txt
  2.  
  3. # cat /tmp/pack1.txt
  4. mariadb-server-5.5.60-1.el7_5.x86_64
  5. perl-DBI-1.627-4.el7.x86_64
  6. perl-DBD-MySQL-4.023-6.el7.x86_64
  7. perl-PlRPC-0.2020-14.el7.noarch
  8. perl-Net-Daemon-0.48-5.el7.noarch
  9. perl-IO-Compress-2.061-2.el7.noarch
  10. perl-Compress-Raw-Zlib-2.061-4.el7.x86_64
  11. mariadb-5.5.60-1.el7_5.x86_64
  12. perl-Data-Dumper-2.145-3.el7.x86_64
  13. perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64
  14. httpd-2.4.6-88.el7.centos.x86_64
  15. mailcap-2.1.41-2.el7.noarch
  16. httpd-tools-2.4.6-88.el7.centos.x86_64
  17. apr-util-1.5.2-6.el7.x86_64
  18. apr-1.4.8-3.el7_4.1.x86_64

方法一:如何在 Linux 上使用 cat 命令安裝文件中列出的包?

為實現(xiàn)這個目標(biāo),我將使用簡單明了的***種方法。為此,創(chuàng)建一個文件并添加上你想要安裝的包列表。

出于測試的目的,我們將只添加以下的三個軟件包名到文件中。

  1. # cat /tmp/pack1.txt
  2.  
  3. apache2
  4. mariadb-server
  5. nano

只要簡單的運行 apt 命令 就能在 Ubuntu/Debian 系統(tǒng)上一次性安裝所有的軟件包。

  1. # apt -y install $(cat /tmp/pack1.txt)
  2.  
  3. Reading package lists... Done
  4. Building dependency tree
  5. Reading state information... Done
  6. The following packages were automatically installed and are no longer required:
  7. libopts25 sntp
  8. Use 'sudo apt autoremove' to remove them.
  9. Suggested packages:
  10. apache2-doc apache2-suexec-pristine | apache2-suexec-custom spell
  11. The following NEW packages will be installed:
  12. apache2 mariadb-server nano
  13. 0 upgraded, 3 newly installed, 0 to remove and 24 not upgraded.
  14. Need to get 339 kB of archives.
  15. After this operation, 1,377 kB of additional disk space will be used.
  16. Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.6 [95.1 kB]
  17. Get:2 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 nano amd64 2.9.3-2 [231 kB]
  18. Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 mariadb-server all 1:10.1.38-0ubuntu0.18.04.1 [12.9 kB]
  19. Fetched 339 kB in 19s (18.0 kB/s)
  20. Selecting previously unselected package apache2.
  21. (Reading database ... 290926 files and directories currently installed.)
  22. Preparing to unpack .../apache2_2.4.29-1ubuntu4.6_amd64.deb ...
  23. Unpacking apache2 (2.4.29-1ubuntu4.6) ...
  24. Selecting previously unselected package nano.
  25. Preparing to unpack .../nano_2.9.3-2_amd64.deb ...
  26. Unpacking nano (2.9.3-2) ...
  27. Selecting previously unselected package mariadb-server.
  28. Preparing to unpack .../mariadb-server_1%3a10.1.38-0ubuntu0.18.04.1_all.deb ...
  29. Unpacking mariadb-server (1:10.1.38-0ubuntu0.18.04.1) ...
  30. Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
  31. Setting up apache2 (2.4.29-1ubuntu4.6) ...
  32. Processing triggers for ureadahead (0.100.0-20) ...
  33. Processing triggers for install-info (6.5.0.dfsg.1-2) ...
  34. Setting up nano (2.9.3-2) ...
  35. update-alternatives: using /bin/nano to provide /usr/bin/editor (editor) in auto mode
  36. update-alternatives: using /bin/nano to provide /usr/bin/pico (pico) in auto mode
  37. Processing triggers for systemd (237-3ubuntu10.20) ...
  38. Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
  39. Setting up mariadb-server (1:10.1.38-0ubuntu0.18.04.1) ...

至于刪除,需要使用相同的命令格式和適當(dāng)?shù)倪x項。

  1. # apt -y remove $(cat /tmp/pack1.txt)
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following packages were automatically installed and are no longer required:
  6. apache2-bin apache2-data apache2-utils galera-3 libaio1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libjemalloc1 liblua5.2-0
  7. libmysqlclient20 libopts25 libterm-readkey-perl mariadb-client-10.1 mariadb-client-core-10.1 mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 mysql-common sntp socat
  8. Use 'apt autoremove' to remove them.
  9. The following packages will be REMOVED:
  10. apache2 mariadb-server nano
  11. 0 upgraded, 0 newly installed, 3 to remove and 24 not upgraded.
  12. After this operation, 1,377 kB disk space will be freed.
  13. (Reading database ... 291046 files and directories currently installed.)
  14. Removing apache2 (2.4.29-1ubuntu4.6) ...
  15. Removing mariadb-server (1:10.1.38-0ubuntu0.18.04.1) ...
  16. Removing nano (2.9.3-2) ...
  17. update-alternatives: using /usr/bin/vim.tiny to provide /usr/bin/editor (editor) in auto mode
  18. Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
  19. Processing triggers for install-info (6.5.0.dfsg.1-2) ...
  20. Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

使用 yum 命令 在基于 RHEL (如 Centos、RHEL (Redhat) 和 OEL (Oracle Enterprise Linux)) 的系統(tǒng)上安裝文件中列出的軟件包。

  1. # yum -y install $(cat /tmp/pack1.txt)

使用以命令在基于 RHEL (如 Centos、RHEL (Redhat) 和 OEL (Oracle Enterprise Linux)) 的系統(tǒng)上卸載文件中列出的軟件包。

  1. # yum -y remove $(cat /tmp/pack1.txt)

使用以下 dnf 命令 在 Fedora 系統(tǒng)上安裝文件中列出的軟件包。

  1. # dnf -y install $(cat /tmp/pack1.txt)

使用以下命令在 Fedora 系統(tǒng)上卸載文件中列出的軟件包。

  1. # dnf -y remove $(cat /tmp/pack1.txt)

使用以下 zypper 命令 在 openSUSE 系統(tǒng)上安裝文件中列出的軟件包。

  1. # zypper -y install $(cat /tmp/pack1.txt)

使用以下命令從 openSUSE 系統(tǒng)上卸載文件中列出的軟件包。

  1. # zypper -y remove $(cat /tmp/pack1.txt)

使用以下 pacman 命令 在基于 Arch Linux (如 Manjaro 和 Antergos) 的系統(tǒng)上安裝文件中列出的軟件包。

  1. # pacman -S $(cat /tmp/pack1.txt)

使用以下命令從基于 Arch Linux (如 Manjaro 和 Antergos) 的系統(tǒng)中卸載文件中列出的軟件包。

  1. # pacman -Rs $(cat /tmp/pack1.txt)

方法二:如何使用 cat 和 xargs 命令在 Linux 中安裝文件中列出的軟件包。

甚至,我更喜歡使用這種方法,因為這是一種非常簡單直接的方法。

使用以下 apt 命令在基于 Debian 的系統(tǒng) (如 Debian、Ubuntu 和 Linux Mint) 上安裝文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs apt -y install

使用以下 apt 命令 從基于 Debian 的系統(tǒng) (如 Debian、Ubuntu 和 Linux Mint) 上卸載文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs apt -y remove

使用以下 yum 命令在基于 RHEL (如 Centos,RHEL (Redhat) 和 OEL (Oracle Enterprise Linux)) 的系統(tǒng)上安裝文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs yum -y install

使用以命令從基于 RHEL (如 Centos、RHEL (Redhat) 和 OEL (Oracle Enterprise Linux)) 的系統(tǒng)上卸載文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs yum -y remove

使用以下 dnf 命令在 Fedora 系統(tǒng)上安裝文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs dnf -y install

使用以下命令從 Fedora 系統(tǒng)上卸載文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs dnf -y remove

使用以下 zypper 命令在 openSUSE 系統(tǒng)上安裝文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs zypper -y install

使用以下命令從 openSUSE 系統(tǒng)上卸載文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs zypper -y remove

使用以下 pacman 命令在基于 Arch Linux (如 Manjaro 和 Antergos) 的系統(tǒng)上安裝文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs pacman -S

使用下以命令從基于 Arch Linux (如 Manjaro 和 Antergos) 的系統(tǒng)上卸載文件中列出的軟件包。

  1. # cat /tmp/pack1.txt | xargs pacman -Rs

方法三 : 如何使用 For 循環(huán)在 Linux 上安裝文件中列出的軟件包

我們也可以使用 for 循環(huán)命令來實現(xiàn)此目的。

安裝批量包可以使用以下一條 for 循環(huán)的命令。

  1. # for pack in `cat /tmp/pack1.txt` ; do apt -y install $i; done

要使用 shell 腳本安裝批量包,請使用以下 for 循環(huán)。

  1. # vi /opt/scripts/bulk-package-install.sh
  2.  
  3. #!/bin/bash
  4. for pack in `cat /tmp/pack1.txt`
  5. do apt -y remove $pack
  6. done

bulk-package-install.sh 設(shè)置可執(zhí)行權(quán)限。

  1. # chmod + bulk-package-install.sh

***運行這個腳本。

  1. # sh bulk-package-install.sh

方法四:如何使用 While 循環(huán)在 Linux 上安裝文件中列出的軟件包

我們也可以使用 while 循環(huán)命令來實現(xiàn)目的。

安裝批量包可以使用以下一條 while 循環(huán)的命令。

  1. # file="/tmp/pack1.txt"; while read -r pack; do apt -y install $pack; done < "$file"

要使用 shell 腳本安裝批量包,請使用以下 while 循環(huán)。

  1. # vi /opt/scripts/bulk-package-install.sh
  2.  
  3. #!/bin/bash
  4. file="/tmp/pack1.txt"
  5. while read -r pack
  6. do apt -y remove $pack
  7. done < "$file"

bulk-package-install.sh 設(shè)置可執(zhí)行權(quán)限。

  1. # chmod + bulk-package-install.sh

***運行這個腳本。

  1. # sh bulk-package-install.sh
責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2018-06-19 10:06:16

Linux軟件測試Nix包管理器

2018-10-15 11:00:28

Linux軟件包命令

2018-09-17 11:35:44

Linux軟件包命令

2019-02-25 09:55:32

UbuntuDebian軟件包

2011-09-15 11:14:12

2018-06-11 08:50:46

LinuxArch Linux降級軟件包

2023-01-02 11:34:04

LinuxFlatpak軟件包

2023-01-03 15:53:00

LinuxFlatpak軟件包

2018-07-10 08:59:07

LinuxArch Linux軟件包

2017-04-08 19:45:27

Linux命令安裝

2019-08-19 11:20:33

Linux軟件包命令

2019-08-19 09:19:02

LinuxVimUbuntu

2010-01-13 10:02:21

LinuxRPM軟件包

2024-01-26 12:35:25

JavaScript項目軟件包

2021-01-06 13:03:22

UbuntuDebianLinux

2016-12-07 17:45:44

Linux文件

2022-06-26 18:23:07

Ubuntu軟件包

2018-10-29 14:10:19

Linux軟件包命令

2022-08-14 08:29:21

npmNode

2020-11-11 08:00:00

Linux系統(tǒng)修復(fù)
點贊
收藏

51CTO技術(shù)棧公眾號