centos7.9常用命令合集
2025-02-12 23:53:37
管理员
CentOS 7.9 常用命令合集
一、系统信息与状态
系统版本与内核
cat /etc/centos-releaseuname -auname -r
资源监控
- 运行状态
uptime - 内存使用
free -h - 磁盘空间
df -hdu -sh * - CPU 信息
lscpucat /proc/cpuinfo
二、文件与目录操作
基础操作
ls -lpwdcd /pathmkdir dirrm -rf dir(谨慎使用)
文件管理
cp file1 file2mv file1 file2touch filecat filehead -n 10 filetail -f file
压缩与解压
- tar 格式
tar -czvf archive.tar.gz dirtar -xzvf archive.tar.gz - zip 格式
zip -r archive.zip dirunzip archive.zip
三、网络管理
地址与配置
- IP 地址
ip addr showifconfig(需安装 net-tools) - 临时配置
ifconfig eth0 192.168.1.100 netmask 255.255.255.0ip addr add 192.168.1.100/24 dev eth0
网络工具
- 连通性测试
ping example.comtraceroute example.com - 端口监听
netstat -tunlp | grep 80ss -tunlp - 服务重启
systemctl restart network
四、软件包管理
YUM 操作
yum updateyum install packageyum remove packageyum search keywordyum list installed
EPEL 仓库
yum install epel-release
RPM 操作
rpm -ivh package.rpmrpm -e packagerpm -qa | grep package
五、用户与权限
用户管理
useradd usernamepasswd usernameuserdel -r username
权限控制
chmod 755 filechown user:group filesu - usernamesudo command
六、服务管理 (systemd)
服务操作
systemctl start httpdsystemctl stop httpdsystemctl restart httpdsystemctl status httpdsystemctl enable httpdsystemctl disable httpd
服务列表
systemctl list-unit-files --type=service
七、磁盘管理
分区与挂载
- 信息查看
fdisk -llsblk - 挂载操作
mount /dev/sdb1 /mntumount /mnt
LVM 管理
pvdisplayvgdisplaylvdisplay
八、进程管理
进程监控
ps aux | grep nginxtophtop(需安装)
进程终止
kill -9 PIDpkill process_name
九、防火墙 (firewalld)
基础操作
systemctl start firewalldfirewall-cmd --statefirewall-cmd --reload
规则配置
- 开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent - 允许服务
firewall-cmd --zone=public --add-service=http --permanent
十、日志管理
日志查看
- 系统日志
journalctl -u nginx.servicejournalctl --since "2023-01-01" --until "2023-01-02" - 文件日志
/var/log/messages/var/log/secure/var/log/httpd/
十一、定时任务
Crontab
crontab -ecrontab -l
at 命令
at now + 5 minutes
十二、SSH 操作
远程连接
ssh user@192.168.1.100 -p 22
密钥管理
- 生成密钥
ssh-keygen -t rsa - 公钥分发
ssh-copy-id user@192.168.1.100
文件传输
十三、系统维护
开关机操作
shutdown -h nowreboot
维护工具
- 缓存清理
sync && echo 3 > /proc/sys/vm/drop_caches - 备份恢复
rsync -avz /source /backuptar -cvpzf backup.tar.gz --exclude=/proc --exclude=/sys /
实用技巧速查
- 公网 IP
curl ifconfig.me - 网络流量
nload(需安装) - 文件搜索
find / -name "filename" - 内存占用排序
ps aux | sort -rnk 4 | head -10
注意事项
- 谨慎使用
rm -rf - 关键操作前备份数据
- 非 root 用户建议通过
sudo提权
标签:
centos