Linux Syscall Table: https://filippo.io/linux-syscall-table/
性能之巅
Linux 命令学习方法 Linux 命令都可以通过 Linux 提供的手册自己学习,一般来讲有三种方式查看命令的用法,如下:
就拿最常用的 ls 命令来举例子吧
第一种:
第二种:
第三种:
View manual pages for commands, programs, and system functions.
Basic Usage 1 man [section] <command_name>
Common Sections
1 : Executable programs (default)
2 : System calls (e.g., man 2 open)
3 : Library functions (e.g., man 3 printf)
5 : File formats (e.g., man 5 passwd)
8 : Admin commands (e.g., man 8 ifconfig)
Key Options
Short
Long
Description
-f
--whatis
Show short description (whatis).
-k
--apropos
Search manuals by keyword (apropos).
-a
--all
Show all matching sections.
Navigation in man
↑/↓ : Scroll line by line.
Space : Next page.
/pattern : Search forward (e.g., /options).
n/N : Next/previous match.
q : Quit.
Examples
View the manual for ls:
Search for manuals about “network”:
Show all sections for open (command + system call):
ℹ️ Pro Tip : Use tldr <command> (if installed) for simplified, practical examples!
大家可以使用 命令 --help, info + 命令, man + 命令 三种方式来学习新的命令,大家也可以使用 The Linux man-pages project 来查找对应的命令。说到这里,让我们来学习下 Linux 的常用网路命令吧
同时,大家还是可以学习下 The Missing Semester of Your CS Education 这门课程,这门课程的讲解非常好,大家可以跟着学习下。中文版本是 计算机教育中缺失的一课 ,B 站上的视频是 计算机教育中缺失的一课 ,大家可以跟着学习下。
Linux 常用网络命令 今天主要跟大家分享下 Linux 系统常用网络的命令:
ifconfig
ifup
ifdown
ip
route
ip route
ping
traceroute
netstat
nslookup
ifconfig 查看所有网卡信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 shenjy@DESKTOP-MCQT724:~$ ifconfig -a eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.2 netmask 255.255.255.0 broadcast 192.168.3.255 ether b4:b6:86:fc :12:07 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.1 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::6715:52aa:2c80:112f prefixlen 64 scopeid 0xfd<compat,link ,site,host> ether 0a:00:27:00:00:03 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth2: flags=64<RUNNING> mtu 1500 inet 169.254.202.32 netmask 255.255.0.0 inet6 fe80::971b:12ac:b88c:961d prefixlen 64 scopeid 0xfd<compat,link ,site,host> ether 7c:76:35:43:62:9f (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.22.96.1 netmask 255.255.240.0 broadcast 172.22.111.255 inet6 fe80::584c:ccd0:e077:634c prefixlen 64 scopeid 0xfd<compat,link ,site,host> ether 00:15:5d:41:e6:ee (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 1500 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0xfe<compat,link ,site,host> loop (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wifi0: flags=64<RUNNING> mtu 1500 inet 169.254.169.148 netmask 255.255.0.0 ether 7c:76:35:43:62:9b (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wifi1: flags=64<RUNNING> mtu 1500 inet 169.254.112.16 netmask 255.255.0.0 ether 7c:76:35:43:62:9c (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wifi2: flags=64<RUNNING> mtu 1500 inet 169.254.241.4 netmask 255.255.0.0 ether 7e:76:35:43:62:9b (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
其余,参数大家可以通过手册自行学习,这里要大家注意下 MTU 这个关键参数,大家可以根据着篇 blog 进行学习。
大家也可以参照这篇 Blog 学习这个命令。
ifup 激活网络接口eth0
1 shenjy@DESKTOP-MCQT724:~$ ifup eth0
大家也可以参照这篇 Blog 学习这个命令。
ifdown 禁用网络端口eth0
1 shenjy@DESKTOP-MCQT724:~$ ifdown eth0
大家也可以参照这篇 Blog 学习这个命令。
ip 查看机器所有网卡的 ip
1 shenjy@DESKTOP-MCQT724:~$ ip a
大家也可以参照这篇 Blog 学习这个命令。
route 查看 Linux 内核路由表
1 shenjy@DESKTOP-MCQT724:~$ route
大家也可以参照这篇 Blog 学习这个命令。
ip route 查看默认路由表(main)路由
1 shenjy@DESKTOP-MCQT724:~$ ip route
大家也可以参照这篇 Blog 学习这个命令。
ping 查看网络链路是否通
1 2 3 shenjy@DESKTOP-MCQT724:~$ ping www.baidu.com shenjy@DESKTOP-MCQT724:~$ ping localhost shenjy@DESKTOP-MCQT724:~$ ping 127.0.0.1
大家也可以参照这篇 Blog 学习这个命令。
traceroute 追踪网络数据包的路由途径,也可以顺道学习下 tracert 这个命令
1 shenjy@DESKTOP-MCQT724:~$ traceroute www.baidu.com
大家也可以参照这篇 Blog 学习这个命令。
netstat Print network connections, routing tables, interface statistics, masquerade connections, and multicast member‐ ships
1 2 3 4 5 6 7 shenjy@DESKTOP-MCQT724:~$ netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 0 0 0 0 0 0 0 0 BMRU eth1 1500 0 0 0 0 0 0 0 0 BMRU eth3 1500 0 0 0 0 0 0 0 0 BMRU lo 1500 0 0 0 0 0 0 0 0 LRU
大家也可以参照这篇 Blog 学习这个命令。
nslookup Nslookup is a program to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive. Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain.
1 2 3 4 5 6 7 shenjy@DESKTOP-MCQT724:~$ nslookup baidu.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: baidu.com Address: 39.156.66.10
大家也可以参照这篇 Blog 学习这个命令。
防火墙相关 firewall-cmd
1 firewall-cmd --list-ports
1 firewall-cmd --zone=public --add-port=80/tcp --permanent
1 firewall-cmd --zone=public --remove-port=80/tcp --permanent
1 systemctl stop firewalld.service
1 systemctl enable /disable firewalld.service
iptables
1 2 3 4 5 6 iptables -L INPUT -n -v netstat -tuln ss -tuln
1 2 3 4 5 6 7 8 iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p udp --dport 53 -j ACCEPT iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 22 -j ACCEPT
注意:使用 iptables 命令添加的规则默认是临时的,系统重启后会丢失。
要使规则永久生效,需要将规则保存到配置文件中(不同的 Linux 发行版有不同的保存工具和方法,例如 iptables-save > /etc/sysconfig/iptables 或使用 iptables-persistent 包)。
1 2 3 4 5 iptables -L INPUT -n --line-numbers iptables -D INPUT <number>
1 2 3 systemctl restart iptables service iptables restart
1 2 3 systemctl stop iptables service iptables stop
1 2 3 4 5 systemctl enable /disable iptables chkconfig iptables on/off update-rc.d iptables enable /disable
查看系统信息
查看系统信息脚本 sysinfo.sh, 使用 chmod +x sysinfo.sh 给脚本添加可执行权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/usr/bin/env bash echo "====== Host / Distro ======" hostnamectl echo ; echo "====== CPU ======" lscpu | grep -E 'Model name|Socket|Core|Thread' echo ; echo "====== Memory ======" free -h echo ; echo "====== Disk ======" lsblk -fp echo ; echo "====== Mount ======" df -hT | grep -E '^/dev' echo ; echo "====== Network ======" ip -br addr echo ; echo "====== Listen Ports ======" ss -tunlp | grep LISTEN echo ; echo "====== Failed Services ======" systemctl list-units --failed
我来为您整理 Linux 常用命令,按功能分类:
📁 文件和目录操作
ls - 列出目录内容
cd - 切换目录
pwd - 显示当前目录
mkdir - 创建目录
rmdir - 删除空目录
rm - 删除文件或目录
cp - 复制文件或目录
mv - 移动或重命名文件
touch - 创建空文件或更新时间戳
find - 查找文件
tree - 以树状图显示目录结构
📄 文件查看和编辑
cat - 查看文件内容
less/more - 分页查看文件
head - 查看文件开头
tail - 查看文件末尾
vi/vim - 文本编辑器
nano - 简单文本编辑器
grep - 搜索文本内容
sed - 流编辑器
awk - 文本处理工具
🔐 权限管理
chmod - 修改文件权限
chown - 修改文件所有者
chgrp - 修改文件所属组
umask - 设置默认权限
👤 用户和组管理
useradd - 添加用户
userdel - 删除用户
passwd - 修改密码
su - 切换用户
sudo - 以管理员权限执行命令
whoami - 显示当前用户
id - 显示用户 ID 信息
💻 系统信息和监控
top/htop - 实时显示进程状态
ps - 查看进程
df - 查看磁盘使用情况
du - 查看目录大小
free - 查看内存使用情况
uname - 显示系统信息
uptime - 系统运行时间
dmesg - 查看系统日志
lscpu - 显示 CPU 信息
lsblk - 列出块设备
🔄 进程管理
kill - 终止进程
killall - 按名称终止进程
pkill - 按模式终止进程
bg - 后台运行任务
fg - 前台运行任务
jobs - 查看后台任务
nohup - 不挂断运行命令
🌐 网络相关
ping - 测试网络连通性
ifconfig/ip - 配置网络接口
netstat - 网络状态
ss - 查看 socket 状态
curl - 传输数据
wget - 下载文件
ssh - 远程登录
scp - 远程复制文件
nslookup/dig - DNS 查询
📦 软件包管理
apt/apt-get - Debian/Ubuntu 包管理
yum/dnf - RedHat/CentOS 包管理
rpm - RPM 包管理
dpkg - Debian 包管理
snap - Snap 包管理
🗜️ 压缩和解压
tar - 打包/解包
gzip/gunzip - gzip 压缩/解压
zip/unzip - zip 压缩/解压
bzip2/bunzip2 - bzip2 压缩/解压
🔍 系统管理
systemctl - 管理系统服务(systemd)
service - 管理服务(传统)
cron/crontab - 定时任务
shutdown/reboot - 关机/重启
mount/umount - 挂载/卸载文件系统
📝 其他常用命令
echo - 输出文本
clear - 清屏
history - 查看命令历史
date - 显示/设置日期时间
man - 查看命令手册
which - 查找命令位置
ln - 创建链接
wc - 统计字数行数
sort - 排序
uniq - 去重
这些是 Linux 系统中最常用的命令。建议您从基础的文件操作命令开始学习,逐步掌握其他类别的命令。使用 man 命令名 可以查看每个命令的详细使用说明。
📊 综合性能监控 top / htop
top - 实时显示系统整体状态和进程信息1 2 3 top top -u username top -p PID
htop - top 的增强版,更直观(需安装)
atop
全面的系统性能监控工具
记录历史数据,可回溯分析
同时监控 CPU、内存、磁盘、网络
glances
跨平台监控工具
自动高亮显示瓶颈
支持 Web 界面
💻 CPU 性能分析 mpstat
vmstat
sar 1 2 3 sar -u 1 10 sar -q 1 10 sar -P ALL 1 10
uptime
pidstat 1 2 pidstat 1 pidstat -p PID 1
🧠 内存性能分析 free 1 2 3 free -h free -m free -s 1
vmstat 1 2 3 4 5 6 7 vmstat -s vmstat -a
sar 1 2 3 sar -r 1 10 sar -B 1 10 sar -W 1 10
slabtop
pmap
smem
💾 磁盘 I/O 性能分析 iostat 1 2 3 4 5 6 7 iostat -x 1 iostat -d 1
iotop
df
du 1 2 du -sh * du -h --max-depth=1
lsof 1 2 3 lsof /path lsof -p PID lsof | grep deleted
fio 1 fio --name=test --rw=randread --bs=4k --size=1G
🌐 网络性能分析 netstat 1 2 3 netstat -tupln netstat -s netstat -i
ss 1 2 3 ss -tupln ss -s ss -o state established
iftop
iptraf / iptraf-ng
nethogs
tcpdump 1 2 tcpdump -i eth0 tcpdump -i eth0 port 80
ping / mtr 1 2 ping example.com mtr example.com
1 2 ethtool eth0 ethtool -S eth0
sar 1 2 3 sar -n DEV 1 10 sar -n TCP 1 10 sar -n SOCK 1 10
🔍 进程性能分析 ps 1 2 3 ps aux ps -ef ps -eo pid,ppid,cmd,%mem,%cpu --sort =-%cpu
pstree
pidstat 1 2 3 pidstat -d 1 pidstat -r 1 pidstat -u 1
strace 1 2 3 strace -p PID strace -c -p PID strace ./program
ltrace
perf 1 2 3 4 perf top perf stat ./program perf record -g -p PID perf report
🔥 火焰图和高级分析 perf + FlameGraph 1 2 3 perf record -F 99 -a -g -- sleep 60 perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > cpu.svg
1 2 3 4 5 opensnoop execsnoop biolatency tcplife
📈 系统日志和诊断 dmesg 1 2 3 dmesg dmesg -T dmesg | grep -i error
journalctl 1 2 3 journalctl -f journalctl -u service journalctl --since "1 hour ago"
sysstat 包
sar - 系统活动报告
iostat - I/O 统计
mpstat - CPU 统计
pidstat - 进程统计
sadf - 数据格式化工具
🛠️ 专项性能工具 CPU 相关
lscpu - CPU 架构信息
turbostat - CPU 频率和功耗
cpupower - CPU 频率管理
内存相关
numactl - NUMA 策略
numastat - NUMA 统计
pcstat - 页缓存统计
磁盘相关
hdparm - 硬盘参数
smartctl - 硬盘健康状态
blktrace - 块层 I/O 跟踪
网络相关
nload - 网络流量实时监控
bmon - 带宽监控
speedtest-cli - 网速测试
iperf3 - 网络性能测试
💡 性能分析方法论 USE 方法(Utilization, Saturation, Errors) 针对每个资源检查:
使用率 (Utilization)- 资源繁忙程度
饱和度 (Saturation)- 等待队列长度
错误 (Errors)- 错误计数
检查清单 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 uptime vmstat 1 mpstat -P ALL 1 pidstat 1 free -m vmstat 1 dmesg | grep -i oom iostat -x 1 iotop sar -n DEV 1 sar -n TCP,ETCP 1 netstat -s
📦 推荐安装的工具包 1 2 3 4 5 6 7 8 9 10 yum install sysstat iotop htop dstat nload iftop nethogs apt install sysstat iotop htop dstat nload iftop nethogs
🎯 快速诊断流程 遇到性能问题时,建议按此顺序检查:
uptime - 快速查看系统负载
dmesg | tail - 检查系统错误
vmstat 1 - 整体资源使用
mpstat -P ALL 1 - CPU 瓶颈?
pidstat 1 - 哪个进程有问题?
iostat -x 1 - 磁盘瓶颈?
free -m - 内存不足?
sar -n DEV 1 - 网络瓶颈?
top - 深入查看
这些工具组合使用,可以全面诊断和解决 Linux 系统的性能问题!