centos7.9常用命令合集
2025-02-12 23:53:37
管理员
CentOS 7.9 常用命令合集
一、系统信息与状态
系统版本与内核
cat /etc/centos-release
uname -a
uname -r
资源监控
- 运行状态
uptime
- 内存使用
free -h
- 磁盘空间
df -h
du -sh *
- CPU 信息
lscpu
cat /proc/cpuinfo
二、文件与目录操作
基础操作
ls -l
pwd
cd /path
mkdir dir
rm -rf dir
(谨慎使用)
文件管理
cp file1 file2
mv file1 file2
touch file
cat file
head -n 10 file
tail -f file
压缩与解压
- tar 格式
tar -czvf archive.tar.gz dir
tar -xzvf archive.tar.gz
- zip 格式
zip -r archive.zip dir
unzip archive.zip
三、网络管理
地址与配置
- IP 地址
ip addr show
ifconfig
(需安装 net-tools) - 临时配置
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ip addr add 192.168.1.100/24 dev eth0
网络工具
- 连通性测试
ping example.com
traceroute example.com
- 端口监听
netstat -tunlp | grep 80
ss -tunlp
- 服务重启
systemctl restart network
四、软件包管理
YUM 操作
yum update
yum install package
yum remove package
yum search keyword
yum list installed
EPEL 仓库
yum install epel-release
RPM 操作
rpm -ivh package.rpm
rpm -e package
rpm -qa | grep package
五、用户与权限
用户管理
useradd username
passwd username
userdel -r username
权限控制
chmod 755 file
chown user:group file
su - username
sudo command
六、服务管理 (systemd)
服务操作
systemctl start httpd
systemctl stop httpd
systemctl restart httpd
systemctl status httpd
systemctl enable httpd
systemctl disable httpd
服务列表
systemctl list-unit-files --type=service
七、磁盘管理
分区与挂载
- 信息查看
fdisk -l
lsblk
- 挂载操作
mount /dev/sdb1 /mnt
umount /mnt
LVM 管理
pvdisplay
vgdisplay
lvdisplay
八、进程管理
进程监控
ps aux | grep nginx
top
htop
(需安装)
进程终止
kill -9 PID
pkill process_name
九、防火墙 (firewalld)
基础操作
systemctl start firewalld
firewall-cmd --state
firewall-cmd --reload
规则配置
- 开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
- 允许服务
firewall-cmd --zone=public --add-service=http --permanent
十、日志管理
日志查看
- 系统日志
journalctl -u nginx.service
journalctl --since "2023-01-01" --until "2023-01-02"
- 文件日志
/var/log/messages
/var/log/secure
/var/log/httpd/
十一、定时任务
Crontab
crontab -e
crontab -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 now
reboot
维护工具
- 缓存清理
sync && echo 3 > /proc/sys/vm/drop_caches
- 备份恢复
rsync -avz /source /backup
tar -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