以下是一些非常实用的 Linux 高级命令和技巧,特别适合程序员和系统管理员提升工作效率:
htop
/ glances
top
更强大的交互式进程查看器,支持鼠标操作和颜色高亮sudo apt install htop
(Debian/Ubuntu) 或 yum install htop
(RHEL/CentOS)glances
提供更全面的系统监控(CPU/内存/磁盘/网络)nmon
nmon -f -s 5 -c 10
(每5秒采样一次,共10次)ss
(替代 netstat
)bash
ss -tulnp # 查看所有监听端口
ss -s # 统计信息
mtr
traceroute
和 ping
的网络诊断工具mtr -n 8.8.8.8
tcpdump
bash
tcpdump -i eth0 port 80 -w capture.pcap
ag
(The Silver Searcher)grep
更快的代码搜索工具ag "function_name" /path/to/code
jq
bash
curl http://api.example.com | jq '.data[] | select(.value > 10)'
rsync
bash
rsync -avz --progress /local/path user@remote:/path
pgrep
/ pkill
bash
pgrep -f "python script.py"
pkill -f "pattern"
nohup
+ disown
bash
nohup ./long_running_script.sh & disown
ncdu
sudo apt install ncdu
ncdu /path/to/scan
iotop
sudo iotop -o
(显示正在使用 I/O 的进程)strace
/ ltrace
bash
strace -f -e trace=file php script.php
perf
bash
perf top # 实时监控
perf record -g ./program # 记录性能数据
auditd
/etc/passwd
:
bash
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
fail2ban
sudo apt install fail2ban
crictl
crictl ps -a
nsenter
bash
nsenter -t <PID> -n ip addr
快速创建大文件:
fallocate -l 1G test.img
查看目录大小:
du -sh * | sort -h
统计代码行数:
find . -name "*.py" | xargs wc -l
生成随机密码:
openssl rand -base64 12
掌握这些命令可以显著提升 Linux 环境下的开发效率。建议收藏常用命令,结合 man
手册深入学习参数用法!