【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