いくつかのケースでは、あなたは別のサーバーにリストサーバにパッケージをインストールすることをお勧めします。たとえば、サーバー上の15個のパッケージをインストールしているし、これらのパッケージは、サーバー上のサーバB、Cなどにインストールする必要があります。
私たちは、ソフトウェアを手動でインストールすることができますが、それは多くの時間がかかります。手動で二つのサーバをインストールしていますが、まだ10サーバーについて持っている場合を想像することができます。この場合は、手動で、その後どのように我々は問題を解決することができ、作業を完了することはできませんか?
私たちは、あなたがこのような状況やシナリオから抜け出すことができます心配しないでください。私たちは、困難を克服するために、この記事では4つのメソッドが追加されました。
私はまた、他のディストリビューションで動作することができます願っています。それが唯一の紙パッケージマネージャのコマンドラインを置き換え公式パッケージマネージャのコマンドのリリースが必要です。
あなたがしたい場合は、すでにインストールされたLinuxシステム上のパッケージのリストを確認し、リンクをクリックしてください。
あなたがRHELシステムをベースにしたパッケージのリストを作成したい場合たとえば、次の手順を使用します。他のディストリビューション、あまりにも。
# rpm -qa --last|head-15| awk '{print $1}'>/tmp/pack1.txt
#cat/tmp/pack1.txt
mariadb-server-5.5.60-1.el7_5.x86_64
perl-DBI-1.627-4.el7.x86_64
perl-DBD-MySQL-4.023-6.el7.x86_64
perl-PlRPC-0.2020-14.el7.noarch
perl-Net-Daemon-0.48-5.el7.noarch
perl-IO-Compress-2.061-2.el7.noarch
perl-Compress-Raw-Zlib-2.061-4.el7.x86_64
mariadb-5.5.60-1.el7_5.x86_64
perl-Data-Dumper-2.145-3.el7.x86_64
perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64
httpd-2.4.6-88.el7.centos.x86_64
mailcap-2.1.41-2.el7.noarch
httpd-tools-2.4.6-88.el7.centos.x86_64
apr-util-1.5.2-6.el7.x86_64
apr-1.4.8-3.el7_4.1.x86_64
方法1:Linux上のファイルにリストされたパッケージをインストールするには、catコマンドを使用するには、どのように?
この目標を達成するために、私は最初の方法は単純明快で使用されます。これを行うには、ファイルを作成し、インストールするパッケージのリストを追加します。
テスト目的のために、私たちは、ファイル名にのみ、以下の3つのパッケージを追加します。
#cat/tmp/pack1.txt
apache2
mariadb-server
nano
単純に実行するのaptコマンドは Ubuntuの/ Debianシステム上のすべてのパッケージを一度だけインストールすることができます。
# apt -y install $(cat/tmp/pack1.txt)
Readingpackage lists...Done
Building dependency tree
Reading state information...Done
The following packages were automatically installed and are no longer required:
libopts25 sntp
Use'sudo apt autoremove' to remove them.
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom spell
The following NEW packages will be installed:
apache2 mariadb-server nano
0 upgraded,3 newly installed,0 to remove and24not upgraded.
Need to get339 kB of archives.
Afterthis operation,1,377 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.6 [95.1 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 nano amd64 2.9.3-2 [231 kB]
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]
Fetched339 kB in19s(18.0 kB/s)
Selecting previously unselected package apache2.
(Reading database ...290926 files and directories currently installed.)
Preparing to unpack .../apache2_2.4.29-1ubuntu4.6_amd64.deb ...
Unpacking apache2 (2.4.29-1ubuntu4.6)...
Selecting previously unselected packagenano.
Preparing to unpack .../nano_2.9.3-2_amd64.deb ...
Unpackingnano(2.9.3-2)...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../mariadb-server_1%3a10.1.38-0ubuntu0.18.04.1_all.deb ...
Unpacking mariadb-server (1:10.1.38-0ubuntu0.18.04.1)...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1)...
Setting up apache2 (2.4.29-1ubuntu4.6)...
Processing triggers for ureadahead (0.100.0-20)...
Processing triggers for install-info(6.5.0.dfsg.1-2)...
Setting up nano(2.9.3-2)...
update-alternatives:using/bin/nano to provide /usr/bin/editor (editor)inauto mode
update-alternatives:using/bin/nano to provide /usr/bin/pico (pico)inauto mode
Processing triggers forsystemd(237-3ubuntu10.20)...
Processing triggers forman-db (2.8.3-2ubuntu0.1)...
Setting up mariadb-server (1:10.1.38-0ubuntu0.18.04.1)...
削除するとして、あなたは同じコマンド形式と適切なオプションを使用します。
# apt -y remove $(cat/tmp/pack1.txt)
Readingpackage lists...Done
Building dependency tree
Reading state information...Done
The following packages were automatically installed and are no longer required:
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
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
Use'apt autoremove' to remove them.
The following packages will be REMOVED:
apache2 mariadb-server nano
0 upgraded,0 newly installed,3 to remove and24not upgraded.
Afterthis operation,1,377 kB disk space will be freed.
(Reading database ...291046 files and directories currently installed.)
Removing apache2 (2.4.29-1ubuntu4.6)...
Removing mariadb-server (1:10.1.38-0ubuntu0.18.04.1)...
Removingnano(2.9.3-2)...
update-alternatives:using/usr/bin/vim.tiny to provide /usr/bin/editor (editor)inauto mode
Processing triggers for ufw (0.36-0ubuntu0.18.04.1)...
Processing triggers for install-info(6.5.0.dfsg.1-2)...
Processing triggers forman-db (2.8.3-2ubuntu0.1)...
#yum-y install $(cat/tmp/pack1.txt)
システム(例えばCentOSに、RHEL(RedHatの)とOEL(のOracle Enterprise Linux)のような)RHELに基づいてファイルにリストされたパッケージをアンインストールするコマンドを使用します。
#yum-y remove $(cat/tmp/pack1.txt)
# dnf -y install $(cat/tmp/pack1.txt)
Fedoraシステム上のファイルにリストされたパッケージをアンインストールするには、次のコマンドを使用します。
# dnf -y remove $(cat/tmp/pack1.txt)
# zypper -y install $(cat/tmp/pack1.txt)
openSUSEのシステムからのファイルに記載されているパッケージをアンインストールするには、次のコマンドを使用します。
# zypper -y remove $(cat/tmp/pack1.txt)
以下の使用パックマンのコマンドの(例えばManjaroとAntergosなど)のアーチLinuxベースのファイルシステムに記載されているインストールパッケージを。
# pacman -S $(cat/tmp/pack1.txt)
中に(例えばManjaroとAntergosなど)のアーチLinuxベースのシステムからファイルに記載されているパッケージをアンインストールするには、次のコマンドを使用します。
# pacman -Rs $(cat/tmp/pack1.txt)
方法2:どのように猫を使用すると、xargsコマンドは、Linuxでのファイルにリストされたパッケージをインストールするコマンド。
これは非常に単純かつ直接的な方法であるためであっても、私は、この方法を使用することを好みます。
以下の使用apt
(などのDebian、UbuntuとLinuxのミントなど)のDebianベースのシステムに記載されているパッケージファイルをインストールするコマンドを。
#cat/tmp/pack1.txt |xargs apt -y install
以下の使用apt
(などのDebian、UbuntuとLinuxのミントなど)Debianシステムからファイルに記載されているパッケージをアンインストールするコマンドをベース。
#cat/tmp/pack1.txt |xargs apt -y remove
以下の使用yum
システム(例えばCentOSに、RHEL(RedHatの)とOEL(のOracle Enterprise Linux)のような)RHELに基づいてファイルにリストされているパッケージをインストールするコマンドを。
#cat/tmp/pack1.txt |xargsyum-y install
である(例えばCentOSに、RHEL(RedHatの)とOEL(のOracle Enterprise Linux)のような)RHELに基づいて、システムからのファイルに記載されているパッケージをアンインストールするコマンドを使用します。
#cat/tmp/pack1.txt |xargsyum-y remove
以下の使用dnf
Fedoraシステム上のファイルに記載されているパッケージをインストールするコマンドを。
#cat/tmp/pack1.txt |xargs dnf -y install
Fedoraシステムからファイルに記載されているパッケージをアンインストールするには、次のコマンドを使用します。
#cat/tmp/pack1.txt |xargs dnf -y remove
以下の使用zypper
のopenSUSEシステムに記載されているパッケージファイルをインストールするコマンドを。
#cat/tmp/pack1.txt |xargs zypper -y install
openSUSEのシステムからのファイルに記載されているパッケージをアンインストールするには、次のコマンドを使用します。
#cat/tmp/pack1.txt |xargs zypper -y remove
以下の使用pacman
の(例えばManjaroとAntergosなど)のアーチLinuxベースのファイルシステムに記載されているパッケージをインストールするコマンドを。
#cat/tmp/pack1.txt |xargs pacman -S
(このようManjaroとAntergosなど)のアーチLinuxベースのシステムからファイルに記載されているコマンドを使用してアンインストールパッケージの下の。
#cat/tmp/pack1.txt |xargs pacman -Rs
方法3:ループのためにリストされたパッケージファイルを使用する方法のLinuxにインストール
また、使用することができfor
、この目的のためにループコマンドを。
バルクパッケージをマウントすると、次のように使用できるfor
サイクルコマンドを。
#for pack in`cat /tmp/pack1.txt`;do apt -y install $i;done
バルクパッケージをインストールするには、シェルスクリプトを使用するには、次のように使用して下さいfor
サイクルを。
#vi/opt/scripts/bulk-package-install.sh
#!/bin/bash
for pack in`cat /tmp/pack1.txt`
do apt -y remove $pack
done
するためにbulk-package-install.sh
実行可能権限を設定します。
#chmod+ bulk-package-install.sh
最後に、このスクリプトを実行します。
# sh bulk-package-install.sh
4:Linux上にインストール循環させながらパッケージ内のファイルを一覧表示する方法
また、使用することができwhile
、コマンドループの目的を達成するために。
バルクパッケージをマウントすると、次のように使用できるwhile
サイクルコマンドを。
#file="/tmp/pack1.txt";while read -r pack;do apt -y install $pack;done<"$file"
バルクパッケージをインストールするには、シェルスクリプトを使用するには、次のように使用して下さいwhile
サイクルを。
#vi/opt/scripts/bulk-package-install.sh
#!/bin/bash
file="/tmp/pack1.txt"
while read -r pack
do apt -y remove $pack
done<"$file"
するためにbulk-package-install.sh
実行可能権限を設定します。
#chmod+ bulk-package-install.sh
最後に、このスクリプトを実行します。
# sh bulk-package-install.sh
経由:https://www.2daygeek.com/how-to-install-uninstall-listed-packages-from-a-file-in-linux/
著者:Magesh Maruthamuthuのトピック:lujun9972翻訳:ウェイ-WW校正:WXY