模板
新一2026-07-10大约 3 分钟-约 757 字
约 757 字大约 3 分钟
2026-07-10
Linux 运维高频常用命令速查手册
一、登录 & 系统基础
# SSH远程登录
ssh root@192.168.1.100
ssh -p 2222 root@192.168.1.100
# 免密登录推送公钥
ssh-copy-id root@192.168.1.100
# 系统信息
cat /etc/os-release # 系统发行版
uname -r # 内核版本
hostname # 主机名
hostnamectl # 完整系统信息
uptime # 开机时长、负载
w # 当前登录用户操作
last # 历史登录记录
# 关机重启
reboot
shutdown -r now # 立即重启
shutdown -h now # 立即关机二、文件 & 目录操作
pwd
ls -lh
ls -A
cd /data/logs
mkdir -p /data/nginx/logs
rm -rf dir/ # 强制删除目录(谨慎)
rm -f *.log
cp -r dir1 dir2
mv old new
# 文件查找
find /data -name "*.log"
find / -size +1G
# 压缩解压
tar zcvf log.tar.gz /data/logs
tar zxvf log.tar.gz -C /tmp
# 文件查看
cat file.txt
less file.log # 分页查看大文件
tail -f nginx.log # 实时跟踪日志
tail -n 1000 nginx.log
head -n 20 file.txt
# 过滤日志
grep "error" nginx.log
grep -i "warn"
grep -v "info"三、权限 & 用户管理
chmod 755 start.sh
chmod +x start.sh
chown -R root:root /data
useradd test
passwd test
userdel -r test
usermod -aG docker test
id test
su - test
sudo -i四、磁盘、内存、负载排查
磁盘空间
df -h
du -sh /*
du -sh /data/*
lsblk
mount /dev/sdb1 /data
umount /data资源负载
free -h
top
vmstat 1
sar -u 1
sar -r 1五、进程 & 端口占用排查
ps -ef | grep nginx
pstree
kill -15 1234
kill -9 1234 # 强制杀进程,慎用
# 端口查询
ss -tulnp
netstat -tulnp
lsof -i :80
lsof -p 1234六、网络 & 防火墙
ip addr
ping 8.8.8.8
ping -c 10 baidu.com
traceroute baidu.com
curl https://www.baidu.com
wget https://xxx.zip
# firewalld(CentOS7/8)
systemctl status firewalld
firewall-cmd --list-ports
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload
# iptables
iptables -L -n七、Systemd 服务管理
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx
systemctl enable nginx
systemctl disable nginx
systemctl status nginx
# 服务日志
journalctl -u nginx -f
journalctl -u nginx --since "2026-07-08 08:00"八、文本 / 日志分析
# 统计报错行数
grep "Exception" app.log | wc -l
# 访问IP统计排序
awk '{print $1}' access.log | sort | uniq -c | sort -nr
# 截取时间段日志
sed '/2026-07-08 10:00/,/2026-07-08 10:30/p' access.log
# 全局替换文件内容
sed -i 's/127.0.0.1/192.168.1.100/g' config.yml九、文件传输同步
# 本地上传服务器
scp local.zip root@192.168.1.100:/data
# 服务器下载本地
scp root@192.168.1.100:/data/log.tar.gz ./
# 增量同步备份
rsync -avz /data root@192.168.1.100:/backup十、软件安装
CentOS/RHEL
yum list installed
yum install nginx -y
yum remove nginx
yum updateUbuntu/Debian
apt list --installed
apt install nginx -y
apt remove nginx
apt update && apt upgrade十一、定时任务 crontab
crontab -l
crontab -e
# 示例:每日凌晨2点执行备份脚本
0 2 * * * /bin/bash /data/script/bak.sh十二、故障急救组合命令
# 磁盘爆满排查
df -h && du -sh /*
# 端口服务异常排查
ss -tulnp | grep 80 && ps -ef | grep nginx
# 实时监控错误日志
tail -f /usr/local/nginx/logs/error.log | grep -i error
# CPU高负载查看进程
top -c
# 查找500M以上大日志文件
find /data -name "*.log" -size +500M运维安全注意事项
rm -rf删除前先用ls确认路径,禁止执行rm -rf /- 关闭进程优先
kill,尽量避免kill -9 - 修改配置文件前备份:
cp nginx.conf nginx.conf.bak - 长时间任务使用
screen会话,防止断连中断操作
