【Linux】常用命令(六)
- 1. yum命令
- 1.1 基本語法
- 1.2 常用命令
- 2. 從服務器把數據cp到本地
- 3. uname命令
- 3.1 常用命令
1. yum命令
- 全稱:Yellowdog Updater, Modified
- 作用:是 RPM 包管理器的前端工具,用于基于 RPM 的 Linux 發行版(如 CentOS、RedHat、Rocky Linux 等)中進行軟件的自動化安裝、更新、刪除和依賴處理。
- 特點:
- 自動解決軟件依賴關系,不需要手動下載安裝依賴包。
- 可以從遠程倉庫獲取軟件包,支持網絡更新。
- 管理方便,常用在服務器上。
1.1 基本語法
yum [options] [command] [package ...]
- options:可選參數,比如 -y 表示自動回答 yes。
- command:操作命令,如 install、update、remove 等。
- package:軟件包名。
1.2 常用命令
1.安裝軟件
yum install 包名
# 如
yum install -y vim
(-y 表示安裝過程中自動回答 "yes")
[root@iv-ye20h65dz45i3z346rvs ~]# yum install -y vim
Loaded plugins: fastestmirror, versionlock
Determining fastest mirrors
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
Package 2:vim-enhanced-7.4.629-8.el7_9.x86_64 already installed and latest version
Nothing to do
2.更新軟件
yum update 包名[root@iv-ye20h65dz45i3z346rvs ~]# yum update vim
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
No packages marked for update
3. 刪除軟件
yum remove 包名
[root@iv-ye20h65dz45i3z346rvs ~]# yum remove vim
Loaded plugins: fastestmirror, versionlock
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be erased
--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================== Package Arch Version Repository Size
========================================================================================================================================Removing:vim-enhanced x86_64 2:7.4.629-8.el7_9 @updates 2.2 MTransaction Summary
========================================================================================================================================Remove 1 PackageInstalled size: 2.2 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionErasing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 Verifying : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 Removed:vim-enhanced.x86_64 2:7.4.629-8.el7_9 Complete!
4.搜索軟件包
yum search 關鍵字
[root@iv-ye20h65dz45i3z346rvs ~]# yum search mysql
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
========================================================== N/S matched: mysql ==========================================================MySQL-python.x86_64 : An interface to MySQL
MySQL-zrm.noarch : MySQL backup manager
akonadi-mysql.x86_64 : Akonadi MySQL backend support
anope-mysql.x86_64 : MariaDB/MySQL modules for Anope IRC services
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
collectd-mysql.x86_64 : MySQL plugin for collectd
dmlite-plugins-mysql.x86_64 : MySQL plugin for dmlite
dovecot-mysql.x86_64 : MySQL back end for dovecot
dpm-copy-server-mysql.x86_64 : DPM copy server with MySQL database back-end
dpm-name-server-mysql.x86_64 : DPM name server with MySQL database back-end
dpm-server-mysql.x86_64 : Disk Pool Manager (DPM) server with MySQL database back-end
dpm-srm-server-mysql.x86_64 : DPM SRM server with MySQL database back-end
dspam-mysql.x86_64 : MySQL storage driver for libdspam
exim-mysql.x86_64 : MySQL lookup support for Exim
freeradius-mysql.x86_64 : MySQL support for freeradius
fts-mysql.x86_64 : File Transfer Service V3 mysql plug-in
gnokii-smsd-mysql.x86_64 : MySQL support for Gnokii SMS daemon
holland-mysql.noarch : MySQL library functionality for Holland Plugins
holland-mysqldump.noarch : Logical mysqldump backup plugin for Holland
holland-mysqllvm.noarch : Holland LVM snapshot backup plugin for MySQL
lfc-server-mysql.x86_64 : LCG File Catalog (LFC) server with MySQL database back-end
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
libgda-mysql.x86_64 : Mysql provider for libgda
libnss-mysql.x86_64 : NSS library for MySQL
libodb-mysql.x86_64 : MySQL ODB runtime library from Code Synthesis
libodb-mysql-devel.x86_64 : Development files for libodb-mysql
lighttpd-mod_authn_mysql.x86_64 : Authentication module for lighttpd that uses a MySQL database
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that uses a MySQL database
mysql++.x86_64 : C++ wrapper for the MySQL C API
mysql++-devel.x86_64 : MySQL++ developer files (headers, examples, etc.)
mysql++-manuals.x86_64 : MySQL++ user and reference manuals
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
mysql-connector-python.noarch : MySQL Connector for Python 2
mysql-mmm.noarch : Multi-Master Replication Manager for MySQL
mysql-proxy.x86_64 : A proxy for the MySQL Client/Server protocol
mysql-proxy-devel.x86_64 : Development files for mysql-proxy
mysql-utilities.noarch : MySQL Utilities
mysqlreport.noarch : A friendly report of important MySQL status values
mysqltuner.noarch : MySQL configuration assistant
nagios-plugins-mysql.x86_64 : Nagios Plugin - check_mysql
nodejs-mysql.noarch : A node.js driver for mysql
opendbx-mysql.x86_64 : MySQL backend - provides mysql support in opendbx
opensips-mysql.x86_64 : MySQL storage support for the OpenSIPS
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
pdns-backend-mysql.x86_64 : MySQL backend for pdns
perdition-mysql.x86_64 : Library to allow perdition to access MySQL based pop maps
perl-Crypt-MySQL.x86_64 : Emulate MySQL PASSWORD() function
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
perl-DateTime-Format-MySQL.noarch : Parse and format MySQL dates and times
perl-Test-mysqld.noarch : Mysqld runner for tests
php-ZendFramework-Db-Adapter-Mysqli.noarch : Zend Framework database adapter for mysqli
php-ZendFramework-Db-Adapter-Pdo-Mysql.noarch : Zend Framework database adapter for MySQL PDO
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-pear-MDB2-Driver-mysql.noarch : MySQL MDB2 driver
php-pear-MDB2-Driver-mysqli.noarch : MySQL Improved MDB2 driver
poco-mysql.x86_64 : The Data/MySQL POCO component
preludedb-mysql.x86_64 : Plugin to use prelude with a MySQL database
proftpd-mysql.x86_64 : Module to add MySQL support to the ProFTPD FTP server
python2-PyMySQL.noarch : Pure-Python MySQL client library
python36-PyMySQL.noarch : Pure-Python MySQL client library
python36-mysql.x86_64 : An interface to MySQL
python36-mysql-debug.x86_64 : An interface to MySQL, built for the CPython debug runtime
qt-mysql.i686 : MySQL driver for Qt's SQL classes
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
qt5-qtbase-mysql.i686 : MySQL driver for Qt5's SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5's SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
root-sql-mysql.x86_64 : MySQL client plugin for ROOT
rsyslog-mysql.x86_64 : MySQL support for rsyslog
soci-mysql.x86_64 : MySQL back-end for soci
soci-mysql-devel.x86_64 : MySQL back-end for soci
tcl-mysqltcl.x86_64 : MySQL interface for Tcl
voms-mysql-plugin.x86_64 : VOMS server plugin for MySQL
wt-dbo-mysql.x86_64 : MySQL back-end for the Wt::Dbo ORM library
zabbix50-proxy-mysql.x86_64 : Zabbix proxy compiled to use MySQL
zabbix50-server-mysql.x86_64 : Zabbix server compiled to use MySQL
zabbix6.0-proxy-mysql.x86_64 : Zabbix proxy compiled to use MySQL
zabbix6.0-server-mysql.x86_64 : Zabbix server compiled to use MySQL
zabbix6.0-web-mysql.noarch : Zabbix web frontend for MySQL
calligra-kexi-driver-mysql.x86_64 : Mysqwl driver for kexi
dmlite-dpmhead.x86_64 : EMI DPM Head Node (MySQL)
dmlite-dpmhead-domeonly.x86_64 : DPM Head Node (MySQL)
innotop.noarch : A MySQL and InnoDB monitor program
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mylvmbackup.noarch : Utility for creating MySQL backups via LVM snapshots
mysql-mmm-agent.noarch : MMM Database Server Agent Daemon and Libraries
mysql-mmm-monitor.noarch : MMM Monitor Server Daemon and Libraries
mysql-mmm-tools.noarch : MMM Control Scripts and Libraries
mytop.noarch : A top clone for MySQL
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB
php-phpmyadmin-sql-parser.noarch : A validating SQL lexer and parser with a focus on MySQL dialect
php-udan11-sql-parser.noarch : A validating SQL lexer and parser with a focus on MySQL dialect
phpMyAdmin.noarch : Handle the administration of MySQL over the World Wide Web
zabbix50-dbfiles-mysql.noarch : Zabbix database schemas, images, data and patches
zabbix6.0-dbfiles-mysql.noarch : Zabbix database schemas, images, data and patchesName and summary matches only, use "search all" for everything.
[root@iv-ye20h65dz45i3z346rvs ~]#
5.查看軟件包信息
yum info 包名
[root@iv-ye20h65dz45i3z346rvs ~]# yum info git
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
Installed Packages
Name : git
Arch : x86_64
Version : 1.8.3.1
Release : 25.el7_9
Size : 22 M
Repo : installed
From repo : updates
Summary : Fast Version Control System
URL : http://git-scm.com/
License : GPLv2
Description : Git is a fast, scalable, distributed revision control system with an: unusually rich command set that provides both high-level operations: and full access to internals.: : The git rpm installs the core tools with minimal dependencies. To: install all git packages, including tools for integrating with other: SCMs, install the git-all meta-package.
6.列出所有可更新的軟件包
[root@iv-ye20h65dz45i3z346rvs opt]# yum list updates
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
Updated Packages
GeoIP.x86_64 1.5.0-14.el7 base
acl.x86_64 2.2.51-15.el7 base
alsa-lib.x86_64 1.1.8-1.el7 base
binutils.x86_64 2.27-44.base.el7_9.1 updatesbiosdevname.x86_64 0.7.3-2.el7 base
ca-certificates.noarch 2023.2.60_v7.0.306-72.el7_9 updateschkconfig.x86_64 1.7.6-1.el7 base
coreutils.x86_64 8.22-24.el7_9.2 updatescpio.x86_64 2.11-28.el7 base
cronie.x86_64 1.4.11-25.el7_9 updatescronie-anacron.x86_64 1.4.11-25.el7_9 updatescryptsetup-libs.x86_64 2.0.3-6.el7 base
7.列出所有已安裝的軟件包
[root@iv-ye20h65dz45i3z346rvs opt]# yum list installed
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
Excluding 2 updates due to versionlock (use "yum versionlock status" to show them)
Installed Packages
GeoIP.x86_64 1.5.0-13.el7 @anaconda
acl.x86_64 2.2.51-14.el7
8.Yum 的軟件倉庫配置文件
[root@iv-ye20h65dz45i3z346rvs opt]# cd /etc/yum.repos.d/
[root@iv-ye20h65dz45i3z346rvs yum.repos.d]# ls
CentOS-Base.repo docker-ce.repo epel.repo epel-testing.repo
常見操作:
-
修改官方源為阿里云、清華等鏡像源,加快下載速度。
-
.repo
文件的結構通常包含: -
[repositoryid]:倉庫 ID
-
name:倉庫說明
-
baseurl:倉庫地址(可本地/網絡)
-
enabled:是否啟用(1=啟用,0=禁用)
-
gpgcheck:是否檢查 GPG 簽名
-
gpgkey:GPG 公鑰路徑
[root@iv-ye20h65dz45i3z346rvs yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.ivolces.com/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.ivolces.com/epel/7/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.ivolces.com/epel/7/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
2. 從服務器把數據cp到本地
把ip為115.190.126.xxx服務器中/root/a.txt
文件復制到本地的E盤
scp -P 22 root@115.190.126.xxx:/root/a.txt E:/
3. uname命令
uname(Unix Name)
是 Linux 和類 Unix 系統中的一個命令,用于顯示系統的相關信息,例如內核名稱、版本、硬件架構、操作系統類型等。
它通常和 -a 參數結合使用,可以一次性查看完整的系統信息。
基本語法:
uname [OPTION]...
如果不加任何參數,默認輸出的是 操作系統的內核名稱(通常是 Linux)。
[root@iv-ye20h65dz45i3z346rvs ~]# uname
Linux
選項 | 含義 | 示例輸出 |
---|---|---|
-s | 內核名稱 (默認行為) | Linux |
-n | 網絡節點主機名 (hostname) | myserver.local |
-r | 內核版本號 | 5.15.0-107-generic |
-v | 內核發布版本(包含編譯日期) | #118-Ubuntu SMP Tue Jun 4 14:53:42 UTC 2024 |
-m | 硬件架構 (machine hardware name) | x86_64 |
-p | 處理器類型(可能返回 unknown ) | x86_64 |
-i | 硬件平臺(可能返回 unknown ) | x86_64 |
-o | 操作系統名稱 | GNU/Linux |
-a | 打印所有信息 | 綜合輸出 |
3.1 常用命令
1.查看系統內核版本
uname -r
# 輸出: 5.15.0-107-generic
2.判斷系統是 32 位還是 64 位
uname -m
# 輸出 x86_64 表示 64 位
# 輸出 i686 / i386 表示 32 位
3.獲取完整的系統信息
uname -a
4.擴展說明
- uname 只顯示內核和硬件相關信息,并不會顯示完整的發行版信息。
如果要查看發行版(如 CentOS、Ubuntu、Debian)的詳細信息,需要用:
cat /etc/os-release
lsb_release -a # 某些系統需要先安裝 lsb_release