Complete list of Linux commands (Part 2)

Complete list of Linux commands (Part 1)

This article directory

6. Common commands for network communication

6.1 ssh command – secure remote connection to server

6.1.1 Meaning

  • sshThe function of the command is to securely connect to the server host system remotely. As a client connection tool in the openssh suite, the sshcommand allows us to easily access the remote hostssh based on the encryption protocol , so as to realize the management of the remote server.

6.1.2 Syntax format

  • ssh [参数] 域名或 IP 地址

6.1.3 Common parameters

parameter meaning
-1 Use ssh protocol version 1
-2 Use ssh protocol version 2
-4 Based on IPv4 network protocol
-6 Based on IPv6 network protocol
-a Turn off the authentication proxy connection forwarding function
-A Enable authentication proxy connection forwarding function
-b Set the IP address of the machine to provide external services
-c Set the password algorithm for the session
-C compress all data
-f Execute ssh commands in the background
-F set configuration file
-g Allow remote hosts to connect to this machine's forwarded port
-i set key file
-l Set login username
-N Do not execute remote commands
-o Set configuration parameter options
-p Set the port number on the remote server
-q silent execution mode
-s request a subsystem call on a remote host
-v Show Execution Details
-V show version information
-x Disable X11 forwarding function
-X Enable X11 forwarding function
-y Trust X11 forwarding functionality

6.1.4 Reference example

  • Based on sshthe protocol, remote access server host system:
ssh 192.168.10.10
  • Log in to the remote server host system as the specified user:
ssh -l linuxprobe 192.168.10.10
  • Execute a command after logging in to the remote server host system:
ssh 192.168.10.10 "free -m"
  • Forcibly use the v1 version of the ssh encryption protocol to connect to the remote server host:
ssh -1 192.168.10.10

6.2 netstat command – display network status

6.2.1 Meaning

  • netstatThe command comes from network statisticsthe abbreviation of the English phrase, and its function is to display various network-related information, such as network connection status, routing table information, interface status, NAT, multicast members, and so on.
  • netstatThe command is not only applied to the Linux system, but also supported by default in Windows XP, Windows 7, Windows 10 and Windows 11, and the available parameters are the same, so experienced operation and maintenance personnel can get started directly.

6.2.2 Syntax format

  • netstat [参数]

6.2.3 Common parameters

parameter meaning
-a Display information about all connected interfaces
-A Set network connection type
-c Continuous display of network status
-C Display routing configuration information
-F show route cache information
-g Display the list of multicast function group members
-h show help information
-i Show web interface information form
-l Only show the status of services that are listening
-n Use the IP address directly, not the domain name
-N Display symbolic link names for network hardware peripherals
-o Display timer data information
-p Display the program ID and name of the interface being used
-r display routing table information
-s Display network work information statistics table information
-t Display the connection status of the TCP transport protocol
-u Display the connection status of the UDP transport protocol
-V show version information

6.2.4 Reference example

  • Display all connection information in the system network status:
netstat -a

在这里插入图片描述

  • Display UDP connection information in system network status:
netstat -nu

在这里插入图片描述

  • Display the UDP connection port number usage information in the system network status:
netstat -apu

在这里插入图片描述

  • Display the current status information of the network card:
netstat -i

在这里插入图片描述

  • Display network routing table status information:
netstat -r

在这里插入图片描述

  • Find the connection information corresponding to a service:
netstat -ap | grep ssh

在这里插入图片描述

6.3 dhclient command – dynamically obtain or release IP address

6.3.1 Meaning

  • dhclientThe command comes from the abbreviation of the English phrase DHCP client, and its function is to dynamically obtain or release an IP address. Before using dhclientthe command, you need to set the network card mode to DHCP to obtain automatically, otherwise the network card in static mode will not actively obtain network card information such as IP address from the server.

6.3.2 Syntax format

  • dhclient 参数 [网卡名]

6.3.3 Common parameters

parameter meaning
-4 Based on IPv4 network protocol
-6 Based on IPv6 network protocol
-d run in foreground
-F Set the FQDN sent to the DHCP server
-H Set the hostname sent to the DHCP server
-n Do not configure any interface
-p Set the port number the DHCP client listens on
-q silent execution mode
-r release IP address
-s Specify a DHCP server before obtaining an IP address
-v Show Execution Details
-V 设置要发送给 DHCP 服务器的厂商类标识符
-w 即使没有找到广播接口,也继续运行
-x 停止 DHCP 客户端,而不释放当前租约
--timeout 设置最大响应超时时间
--version 显示版本信息

6.3.4 参考示例

  • 通过指定网卡发起 DHCP 请求,获取网卡参数:
dhclient ens33
  • 释放系统中已获取的网卡参数:
dhclient -r
  • 向指定的服务器请求获取网卡参数:
dhclient -s 192.168.10.10
  • 手动停止执行 dhclient 服务进程:
dhclient -x

6.4 ifconfig 命令 – 显示或设置网络设备参数信息

6.4.1 含义

  • ifconfig 命令来自英文词组 network interfaces configuring 的缩写,其功能是用于显示或设置网络设备参数信息。在 Windows 系统中与之类似的命令叫做 ipconfig,同样的功能可以使用 ifconfig 去完成。
  • 通常不建议使用 ifconfig 命令配置网络设备的参数信息,因为一旦服务器重启,配置过的参数会自动失效,还是编写到配置文件中更稳妥。

6.4.2 语法格式

  • ifconfig [参数] [网卡名] [动作]

6.4.3 常用参数

参数 含义
-a 显示所有网卡状态
-s 显示简短状态列表
-v 显示执行过程详细信息

6.4.4 常用动作

add 设置网络设备的 IP 地址
del 删除网络设备的 IP 地址
down 关闭指定的网络设备
up 启动指定的网络设备

6.4.5 参考示例

  • 显示系统的网络设备信息:
ifconfig
  • 对指定的网卡设备依次进行关闭和启动操作:
ifconfig ens33 down
ifconfig ens33 up
  • 对指定的网卡设备执行修改 IP 地址操作:
ifconfig ens33 192.168.10.20 netmask 255.255.255.0
  • 对指定的网卡设备执行修改 MAC 地址操作:
ifconfig ens33 hw ether 00:aa:bb:cc:dd:ee
  • 对指定的网卡设备依次进行 ARP 协议关闭和开启操作:
ifconfig ens33 -arp
ifconfig ens33 arp

6.4.6 补充

  • ifconfig 可以查看/配置计算机当前的网卡配置信息。
# 查看网卡配置信息
$ ifconfig

# 查看网卡对应的 IP 地址
$ ifconfig | grep inet

提示:一台计算机中有可能会有一个物理网卡和多个虚拟网卡,在 Linux 中物理网卡的名字通常以 ensXX 表示。

  • 127.0.0.1 被称为本地回环/环回地址,一般用来测试本机网卡是否正常。

6.5 ping 命令 – 测试主机间网络连通性

6.5.1 含义

  • ping 命令的功能是用于测试主机间网络连通性,发送出基于 ICMP 传输协议的数据包,要求对方主机予以回复,若对方主机的网络功能没有问题且防火墙放行流量,则就会回复该信息,我们也就可得知对方主机系统在线并运行正常了。
  • 不过值得我们注意的是 Linux 与 Windows 相比有一定差异,Windows 系统下的 ping 命令会发送出去 4 个请求后自动结束该命令;而 Linux 系统则不会自动终止,需要用户手动按下组合键“Ctrl+c”才能结束,或是发起命令时加入 -c 参数限定发送个数。

6.5.2 语法格式

  • ping [参数] 域名或IP地址

6.5.3 常用参数

参数 含义
-4 基于 IPv4 网络协议
-6 基于 IPv6 网络协议
-a 发送数据时发出鸣响声
-b 允许 ping 一个广播地址
-c 设置发送报文的次数
-d 使用接口的 SO_DEBUG 功能
-f 使用洪泛模式大量向目标发送数据包
-h 显示帮助信息
-i 设置收发信息的间隔时间
-I 使用指定的网络接口送出数据包
-n 仅输出数值
-p 设置填满数据包的范本样式
-q 静默执行模式
-R 记录路由过程信息
-s 设置数据包的大小
-t 设置存活数值TTL的大小
-v 显示执行过程详细信息
-V 显示版本信息

6.5.4 参考示例

  • 测试与指定网站服务器之间的网络连通性(需手动按下“Ctrl+c”组合键结束命令):
ping www.linuxcool.com
  • 测试与指定网站服务器之间的网络连通性,发送请求包限定为 4 次:
ping -c 4 www.linuxcool.com

在这里插入图片描述

  • 测试与指定主机之间的网络连通性,发送 3 次请求包,每次间隔 0.2 秒,最长等待时间为 3 秒:
ping -c 3 -i 0.2 -W 3 192.168.10.10

在这里插入图片描述

6.6 sshd 命令 – openssh 服务器守护进程

6.6.1 含义

  • sshd 命令来自英文词组 SSH daemon 的缩写,其功能是用于 openssh 服务器守护进程。openssh 套件能够为两台主机之间建立加密的、可信任的数据通信服务,是 rlogin 与 rsh 等明文数据通信的替代品,而 sshd 命令即为 openssh 套件中的核心程序。

6.6.2 语法格式

  • sshd [参数] [对象]

6.6.3 常用参数

参数 含义
-4 基于 IPv4 网络协议
-6 基于 IPv6 网络协议
-d 使用调试模式
-D 使用非后台守护进程的方式运行服务
-e 直接显示报错信息
-f 设置服务器的配置文件
-g 设置客户端登录的过期时间
-h 设置读取主机密钥文件
-i 使用 inetd 方式运行
-o 设置服务配置选项
-p 设置使用的端口号
-q 静默执行模式
-t 使用测试模式

6.6.4 参考示例

  • 以调试模式运行 sshd 服务程序:
/usr/sbin/sshd -d
  • 以测试模式运行 sshd 服务程序:
/usr/sbin/sshd -t
  • 强制基于 IPv6 地址进行服务:
/usr/sbin/sshd -6

7. 设备管理 常用命令

7.1 mount 命令 – 将文件系统挂载到目录

7.1.1 含义

  • mount 命令的功能是用于将文件系统挂载到目录,文件系统指的是被格式化过的硬盘或分区设备,进行挂载操作后,用户便可以在挂载目录中使用硬盘资源了。
  • 默认情况下 Linux 系统并不会像 Windows 系统那样自动地挂载光盘和U盘设备,需要自行完成。

7.1.2 语法格式

  • mount [参数] [设备名] [目录名]

7.1.3 常用参数

参数 含义
-a 加载“/etc/fstab”文件中记录的所有文件系统
-F 为每个设备创建出一个新的挂载版本
-h 显示帮助信息
-l 显示已加载的文件系统列表
-L 挂载具有指定标签的分区
-n 加载没有写入“/etc/mtab”文件中的文件系统
-r 将文件系统设置为只读模式
-t 挂载指定文件类型的设备分区
-U 挂载指定 UUID 的设备分区
-V 显示版本信息
-w 以读写方式挂载文件系统

7.1.4 参考示例

  • 查看当前系统中已有的文件系统信息:
mount
  • 挂载 /etc/fstab 文件中所有已定义的设备文件:
mount -a
  • 将光盘设备挂载到指定目录:
mount /dev/cdrom /Dir
  • 强制以xfs文件系统挂载硬盘设备到指定目录:
mount -t xfs /dev/sdb /Dir

7.2 lspci 命令 – 显示当前设备 PCI 总线设备信息

7.2.1 含义

  • lspci 命令来自英文词组 list PCI 的缩写,其功能是用于显示当前设备 PCI 总线设备信息

7.2.2 语法格式

  • lspci [参数] [设备名]

7.2.3 常用参数

参数 含义
-b 使用以总线为中心的视图
-d 仅显示指定厂商和设备信息
-i 设置 PCI 编号列表文件
-m 以机器可读方式显示 PCI 设备信息
-M 使用总线映射模式
-n 以数字方式显示 PCI 设备信息
-nn 将 PCI 厂商和设备代码显示为数字和名称形式
-q 使用 DNS 查询中央 PCI ID 数据库
-p 设置包含 PCI 总线信息的目录
-s 仅显示指定总线插槽的设备和功能块信息
-t 使用树状结构显示 PCI 设备的层次关系
-v 显示执行过程详细信息

7.2.4 参考示例

  • 显示当前主机的所有PCI总线设备信息:
lspci
  • 以树状结构显示当前主机的所有 PCI 总线设备信息:
lspci -t

7.3 sensors 命令 – 检测服务器硬件信息

7.3.1 含义

  • sensors 命令用于检测服务器硬件信息,例如 CPU 电压与温度、主板、风扇转速等数据。

7.3.2 语法格式

  • sensors

7.3.3 常用参数

参数 含义
-A 不显示每个芯片的适配器信息
-c 指定配置文件
-F 显示华氏度温度
-H 显示帮助信息
-u 输出原始信息
-v 显示版本信息

7.3.4 参考示例

  • 检查当前 CPU 处理器得电压和温度信息:
sensors

8. 备份压缩 常用命令

8.1 zip 命令 – 压缩文件

8.1.1 含义

  • zip 命令的功能是用于压缩文件,解压命令为 unzip。通过 zip 命令可以将文件打包成 .zip 格式的压缩包,里面会包含文件的名称、路径、创建时间、上次修改时间等等信息,与 tar 命令相似。

8.1.2 语法格式

  • zip 参数 目标文件.zip 源文件或目录名

8.1.3 常用参数

参数 含义
-A 自动解压缩文件
-b 设置暂存文件的目录
-c 添加注释信息到压缩文件
-d 更新压缩包内文件
-F 尝试修复损坏的压缩文件
-h 显示帮助信息
-i 仅压缩符合条件的文件
-k 使用MS-DOS兼容格式
-l 将“LF”替换成“LF+CR”字符
-L 显示版本信息
-m 压缩后删除源文件
-n 不压缩具有特定字符串的文件
-q 静默执行模式
-r 递归处理所有子文件
-S 包含系统和隐藏文件
-t 设置压缩时间为指定日期
-T 检查压缩文件是否正确无误
-v 显示执行过程详细信息
-V 保留VMS操作系统的文件属性
-w 在文件名称中加入版本编号
-X 不保留过多的文件属性信息
-y 直接保存符号链接,而不是对应文件

8.1.4 参考示例

  • 将指定目录及其内全部文件都打包成 zip 格式压缩包文件:
zip -r File.zip /etc
  • 将当前工作目录内所有以 .cfg 为后缀的文件打包:
zip -r File.zip *.cfg
  • 更新压缩包文件中某个文件:
zip -dv File.zip File.cfg

8.2 unzip 命令 – 解压缩 zip 格式文件

8.2.1 含义

  • unzip 命令用于解压缩 zip 格式文件,虽然 Linux 系统中更多地使用 tar 命令进行对压缩包的管理操作,但有时也会收到 Windows 系统常用的 .zip.rar 格式的压缩包文件,unzip 命令便派上了用场。直接使用 unzip 命令解压缩文件后,压缩包内原有的文件会被提取并输出保存到当前工作目录下。

8.2.2 语法格式

  • unzip [参数] 压缩包名

8.2.3 常用参数

参数 含义
-a 对文本进行必要的字符转换
-b 不要对文本进行任何字符转换
-c 适当转换字符后输出解压缩结果
-C 严格区分大小写
-d 解压缩文件到指定目录中
-f 强制覆盖已有文件
-j 不处理压缩文件中原有的目录路径
-l 显示压缩包内文件列表
-L 将压缩包内文件名改为小写
-n 解压缩时不覆盖已有文件
-p 使用密码加密
-q 静默执行模式
-t 检查压缩包完整性
-v 显示执行过程详细信息
-x 跳过压缩包内的指定文件
-z 显示压缩包内的备注文字

8.2.4 参考示例

  • 将压缩包文件解压到当前工作目录中:
unzip File.zip
  • 将压缩包文件解压到指定目录中:
unzip File.zip -d /home
  • 测试压缩包文件是否完整,文件有无损坏:
unzip -t File.zip

8.3 gzip 命令 – 压缩和解压文件

8.3.1 含义

  • gzip 命令来自英文单词 gunzip 的缩写,其功能是用于压缩和解压文件。gzip 是一款使用广泛的压缩工具,文件经过压缩后一般会以 .gz 后缀结尾,与 tar 命令合用后即为 .tar.gz 后缀。
  • 据统计,gzip 命令对文本文件的压缩比率通常能达到60%~70%,压缩后可以很好地提升存储空间的使用率,还能够在网络传输文件时减少等待时间。

8.3.2 语法格式

  • gzip [参数] 文件名

8.3.3 常用参数

参数 含义
-a 使用 ASCII 文本模式
-c 把压缩后的文件输出到标准输出设备
-d 解压指定压缩包文件
-f 强行压缩文件而不询问
-h 显示帮助信息
-k 保留原文件
-l 显示压缩包内的文件信息
-L 显示版权信息
-n 不保存原来的文件名及时间戳
-N 保存原来的文件名及时间戳
-t 测试压缩包是否正确无误
-q 静默执行模式
-r 递归处理所有子文件
-S 设置解压或压缩后文件的后缀名
-v 显示执行过程详细信息
-V 显示版本信息

8.3.4 参考示例

  • 将指定的文件进行压缩,压缩包默认会以“原文件名.gz”保存到当前工作目录下,原文件会被自动删除:
gzip File.cfg
  • 解压指定的压缩包文件并显示解压过程,解压后的文件会保存在当前工作目录下,压缩包会被自动删除:
gzip -dv File.cfg.gz
  • 将指定的文件进行压缩,但是不删除原文件:
gzip -k File.cfg
  • 显示指定文件的压缩信息:
gzip -l File.cfg.gz

9. 其它常用命令

9.1 hash 命令 – 管理命令运行时查询的哈希表

9.1.1 含义

  • hash 命令来自英文词组 Hash Algorithm 的缩写,中文译为哈希算法或杂凑算法,其功能是用于管理命令运行时查询的哈希表hash 命令可以显示与删除命令运行时系统查询的哈希表信息,如果不加任何参数,则会默认输出路径列表的信息,这个列表会包含先前 hash 命令调用找到的 Shell 环境中命令的路径名。

9.1.2 语法格式

  • hash [参数] [目录名]

9.1.3 常用参数

参数 含义
-f 设置要进行哈希运算的文件路径
-l 显示哈希表中的命令
-p 将完整路径的命令加入到哈希表中
-r 清除哈希表中的记录
-t 显示哈希表中命令的完整路径
--help 显示帮助信息
--verbose 显示执行过程详细信息

9.1.4 参考示例

  • 显示哈希表中的命令:
hash -l
  • 删除哈希表中的命令:
hash -r
  • 向哈希表中添加命令:
hash -p /usr/sbin/adduser myadduser 
  • 在哈希表中清除记录:
hash -d 

9.2 wait 命令 – 等待指令执行完毕

9.2.1 含义

  • wait 命令的功能是用于等待指令执行完毕,常被用于 Shell 脚本中,用于等待某个指令执行结束后返回终端,然后才会继续执行后面的指令。
  • 例如有个服务进程 PID 为 12345,那么此时可以用 wait 12345 来持续等待此进程的结束,一旦进程结束则会将返回值输出到终端界面。

9.2.2 语法格式

  • wait 进程号或%作业号

9.2.3 常用参数

参数 含义
数字 进程号
%数字 %作业号

9.2.4 参考示例

  • 等待执行的进程结束并输出返回值:
wait 12345

9.3 wget 命令 – 下载网络文件

9.3.1 含义

  • wget 命令来自英文词组 web get 的缩写,其功能是用于从指定网址下载网络文件。wget 命令非常稳定,一般即便网络波动也不会导致下载失败,而是不断地尝试重连,直至整个文件下载完毕。
  • wget 命令支持如 HTTP、HTTPS、FTP 等常见协议,可以在命令行中直接下载网络文件。

9.3.2 语法格式

  • wget [参数] 网址URL [对象]

9.3.3 常用参数

参数 含义
-4 基于 IPv4 网络协议
-6 基于 IPv6 网络协议
-a 将日志追加写入至指定文件
-b 启动后转入后台执行
-c 支持断点续传
-d 使用调试模式
-e 执行指定的命令
-F 将输入文件当作 HTML 处理
-h 显示帮助信息
-i 下载指定文件中的链接
-l 设置最大递归目录深度
-nd 不要创建目录
-N 只获取比本地更新的文件
-o 将日志信息写入指定文件
-O 设置本地文件名
-P 设置文件前缀
-q 静默执行模式
-r 递归处理所有子文件
-S 显示服务器响应信息
-t 设置最大尝试次数
-T 设置最长等待时间
-v 显示执行过程详细信息
-V 显示版本信息
-w 设置等待间隔秒数
-x 强制创建目录
--ask-password 提示输入密码
--limit-rate 限制下载速度
--no-dns-cache 关闭DNS查询缓存
--no-proxy 禁止使用代理
--password 设置密码值
--random-wait 下载多个文件时,随机等待间隔秒数
--spider 仅检查文件是否存在
--user 设置用户名

9.3.4 参考示例

  • 下载指定的网络文件:
wget https://www.linuxprobe.com/docs/LinuxProbe.pdf
  • 下载指定的网络文件,并定义保存在本地的文件名称:
wget -O Book.pdf https://www.linuxprobe.com/docs/LinuxProbe.pdf 
  • 下载指定的网络文件,限速最高每秒300k:
wget --limit-rate=300k https://www.linuxprobe.com/docs/LinuxProbe.pdf 
  • 启用断点续传技术下载指定的网络文件:
wget -c https://www.linuxprobe.com/docs/LinuxProbe.pdf 
  • 下载指定的网络文件,将任务放至后台执行:
wget -b https://www.linuxprobe.com/docs/LinuxProbe.pdf

Guess you like

Origin blog.csdn.net/m0_51913750/article/details/131625340