Ubuntu 常用命令整理
2026-11-20 · Linux
系统信息
uname -a # 内核
lsb_release -a # 发行版
nproc # CPU 核数
free -h # 内存
df -h / # 磁盘
uptime # 负载
服务管理
systemctl status nginx
systemctl restart nginx
journalctl -u nginx -n 50 --no-pager
systemctl list-units --type=service --state=running
端口与连接
ss -tlnp # 监听端口
ss -tnp | grep ESTAB # 已建立连接
lsof -i :443 # 谁占着 443
防火墙
ufw status verbose
ufw allow 443/tcp
ufw delete allow 443/tcp
iptables -S | head -20
网络排查
ping -f -l 1472 1.1.1.1 # MTU 探测(Windows)
traceroute 1.1.1.1
mtr -rw 1.1.1.1 # 持续丢包统计
curl -vI https://example.com
文件与压缩
tar -czf a.tar.gz dir/
tar -xzf a.tar.gz -C /opt/
du -sh * | sort -h | tail
find /var/log -name "*.log" -mtime +7 -delete