常用命令速查
银河麒麟服务器核心运维指令快速索引指南
1. 系统信息查询
查看系统版本
cat /etc/kylin-release
# 或
cat /etc/os-release
查看内核版本
uname -r
# 详细信息
uname -a
查看CPU信息
lscpu
# 或查看详细信息
cat /proc/cpuinfo
查看内存使用
free -h
# 详细内存信息
cat /proc/meminfo
查看磁盘空间
df -h
# 查看 inode 使用
df -i
查看磁盘分区
lsblk
# 详细分区信息
fdisk -l
查看系统负载
uptime
# 或
w
查看系统运行时间
uptime -p
2. 服务管理 (systemctl)
启动服务
systemctl start nginx
停止服务
systemctl stop nginx
重启服务
systemctl restart nginx
重新加载配置(不中断服务)
systemctl reload nginx
查看服务状态
systemctl status nginx
设置开机自启
systemctl enable nginx
禁止開機自啟
systemctl disable nginx
启动并设置开机自启(組合)
systemctl enable nginx --now
查看所有运行中的服务
systemctl list-units --type=service --state=running
查看服务启动失败原因
systemctl status nginx -l
journalctl -u nginx -f
3. 软件包管理 (yum/dnf)
安装软件
yum install nginx -y
# 或
dnf install nginx -y
卸载软件
yum remove nginx -y
搜索软件
yum search nginx
查看软件包信息
yum info nginx
列出已安装的包
yum list installed
更新单个软件
yum update nginx -y
更新所有软件包
yum update -y
清理缓存
yum clean all
重建缓存
yum makecache
查看软件包提供的文件
rpm -ql nginx
查看文件属于哪个包
rpm -qf /usr/sbin/nginx
安装本地rpm包
yum localinstall package.rpm -y
# 或
rpm -ivh package.rpm
4. 网络相关
查看IP地址
ip addr
# 简介
ip a
查看网络接口状态
nmcli device status
查看端口监听
ss -tlnp
# 查看所有连接(包括UDP)
ss -tulnp
查看网络连接统计
ss -s
测试网络连通性
ping -c 4 8.8.8.8
测试端口连通性
telnet 192.168.1.1 22
# 或使用nc
nc -zv 192.168.1.1 22
查看路由表
ip route
# 或
route -n
DNS解析测试
nslookup www.baidu.com
# 或
dig www.baidu.com
查看网络流量
# 安装 iftop
yum install iftop -y
iftop -i eth0
5. 进程管理
查看所有进程
ps aux
查看进程树
pstree -p
按CPU使用排序
ps aux --sort=-%cpu | head -20
按内存使用排序
ps aux --sort=-%mem | head -20
查找特定进程
ps aux | grep nginx
# 或
pgrep -a nginx
终止进程
# 优雅终止
kill PID
# 强制终止
kill -9 PID
按名称终止进程
pkill nginx
# 强制
pkill -9 nginx
实时监控 (top/htop)
top
# 安装并使用htop(更友好)
yum install htop -y
htop
6. 文件与目录操作
创建目录
mkdir -p /path/to/directory
复制文件/目录
# 复制文件
cp source dest
# 递归复制目录
cp -r source_dir dest_dir
移动/重命名
mv oldname newname
删除文件/目录
# 删除文件
rm file
# 递归删除目录
rm -rf directory
查找文件
# 按名称查找
find /path -name "*.log"
# 按大小查找(大于100MB)
find /path -size +100M
查看文件内容
# 查看全部
cat file
# 分页查看
less file
# 查看前N行
head -n 20 file
# 查看後N行
tail -n 20 file
# 实时查看
tail -f file
文件搜索内容
# 在文件中搜索
grep "keyword" file
# 递归搜索目录
grep -r "keyword" /path/
查看目录大小
du -sh /path/
# 列出子目录大小
du -h --max-depth=1 /path/
7. 壓縮與解壓縮
tar.gz 压缩
tar -czvf archive.tar.gz directory/
tar.gz 解压
tar -xzvf archive.tar.gz
# 解压到指定目录
tar -xzvf archive.tar.gz -C /target/
zip 压缩
zip -r archive.zip directory/
zip 解压
unzip archive.zip
8. 用户与权限
切换用户
su - username
# 切换到root
sudo -i
查看当前用户
whoami
id
修改文件权限
chmod 755 file
chmod +x script.sh
修改文件所有者
chown user:group file
chown -R user:group directory/
9. 日志查看
查看系统日志
journalctl -f
# 查看今天的日志
journalctl --since today
查看服务日志
journalctl -u nginx -f
查看启动日志
dmesg | tail -50
查看登录日志
last
# 查看失败登录
lastb