ubuntu之查看所有服务:
$ systemctl list-unit-files -t service
UNIT FILE STATE VENDOR PRESET
accounts-daemon.service enabled enabled
acpid.service disabled enabled
alsa-restore.service static -
alsa-state.service static -
alsa-utils.service masked enabled
anacron.service enabled enabled
apparmor.service enabled enabled
apport-autoreport.service static -
apport-forward@.service static -
apport.service generated -
apt-daily-upgrade.service static -
apt-daily.service static -
apt-news.service static -
autovt@.service alias -
avahi-daemon.service enabled enabled
bluetooth.service enabled enabled
bolt.service static -
brltty-udev.service static -
brltty.service disabled enabled
colord.service static -
...
...
ubuntu之查指定服务运行状态
$ ps aux | grep nginx
root 1155 0.0 0.0 84836 2760 ? Ss 13:35 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
root+ 1156 0.0 0.0 85500 6472 ? S 13:35 0:00 nginx: worker process
root+ 1157 0.0 0.0 85500 6472 ? S 13:35 0:00 nginx: worker process
root+ 1158 0.0 0.0 85500 6472 ? S 13:35 0:00 nginx: worker process
root+ 1159 0.0 0.0 85500 6600 ? S 13:35 0:00 nginx: worker process
root+ 1160 0.0 0.0 85500 6344 ? S 13:35 0:00 nginx: worker process
root+ 1161 0.0 0.0 85500 6344 ? S 13:35 0:00 nginx: worker process
root+ 1162 0.0 0.0 85500 6344 ? S 13:35 0:00 nginx: worker process
...
...
// 参数解析
a → 显示所有终端下的进程,包括其他用户的。
u → 以用户为中心的格式显示,包含用户、CPU/内存占用等。
x → 显示没有控制终端的进程(例如守护进程)。
ubuntu之查所有服务运行状态
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 167468 11956 ? Ss 13:35 0:05 /sbin/init splash
root 2 0.0 0.0 0 0 ? S 13:35 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 13:35 0:00 [pool_workqueue_release]
root 4 0.0 0.0 0 0 ? I< 13:35 0:00 [kworker/R-rcu_g]
root 5 0.0 0.0 0 0 ? I< 13:35 0:00 [kworker/R-rcu_p]
...
...
//参数解析
USER → 进程所属用户
PID → 进程 ID
%CPU → 占用 CPU 百分比
%MEM → 占用物理内存百分比
VSZ → 占用的虚拟内存大小(KB)
RSS → 实际常驻内存大小(KB)
TTY → 进程的控制终端(? 表示无终端)
STAT → 进程状态(例如 S=睡眠,R=运行,Z=僵尸,T=停止)
START → 进程启动时间
TIME → 占用 CPU 的累计时间
COMMAND → 启动进程的命令
ubuntu之查指定端口
$ netstat -tnlp | grep 80
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN 1156/nginx: worker
tcp 0 0 0.0.0.0:9080 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp6 0 0 :::9080 :::* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
...
...
// 参数解析
-t → TCP
-n → 显示数字地址(不做域名反查)
-l → 只显示监听状态的端口
-p → 显示对应的进程 PID/程序名
ubuntu之查所有端口
$ netstat -tnlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:43817 0.0.0.0:* LISTEN 8127/clash-linux
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN 1156/nginx: worker
tcp 0 0 0.0.0.0:8109 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8108 0.0.0.0:* LISTEN -
...
...
// 参数解析
Proto → 协议类型
tcp → IPv4 TCP
tcp6 → IPv6 TCP
Recv-Q → 接收队列中未被应用程序取走的数据(一般为 0,如果不是 0,可能表示应用处理不过来)
Send-Q → 发送队列中未被对方确认的数据(一般为 0,如果不是 0,可能表示网络拥塞或应用未读取)
Local Address → 本地监听的地址和端口
0.0.0.0:22 → 监听所有 IPv4 地址的 22 端口
:::80 → 监听所有 IPv6 地址的 80 端口
Foreign Address → 对端地址(监听状态下一般是 *,表示未建立连接)
State → 当前连接状态
常见值:LISTEN、ESTABLISHED、TIME_WAIT、CLOSE_WAIT
PID/Program name → 占用端口的进程 PID 和程序名
1234/sshd 表示 PID=1234 的 sshd 占用
常见情况解释
0.0.0.0:80
→ 监听所有网卡的 IPv4 地址 80 端口(外部可访问)。
127.0.0.1:3306
→ 仅监听本机回环地址(外部不能访问,只能本机连接)。
:::443
→ 监听所有 IPv6 地址的 443 端口
