系统信息查询
查看系统版本
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
服务管理(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
软件包管理(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
网络相关
查看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
进程管理
查看所有进
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
文件与目录操
创建目录
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/
压缩与解
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
用户与权
切换用户
su - username
# 切换到root
sudo -i
查看当前用户
whoami
id
修改文件权限
chmod 755 file
chmod +x script.sh
修改文件所有
chown user:group file
chown -R user:group directory/
日志查看
查看系统日志
journalctl -f
# 查看今天的日?
journalctl --since today
查看服务日志
journalctl -u nginx -f
查看启动日志
dmesg | tail -50
查看登录日志
last
# 查看失败登录
lastb