Appearance

linux常用命令

coderzhouyu2023/10/4

端口占用

# 查看端口占用 t tcp u udp n 显示端口号 p 显示进程名
netstat -tunlp | grep 端口号
# 查看端口占用
lsof -i:端口号
# 查看端口占用
lsof -i:端口号 | grep LISTEN

查看进程

# 查看所有进程
ps -ef
# 查看指定进程
ps -ef | grep 进程名

杀死进程

# 杀死指定进程
kill -9 进程号

查看文件

# 查看文件内容
cat 文件名
# 查看文件内容并分页
more 文件名
# 查看文件内容并分页
less 文件名
# 查看文件内容并分页
head 文件名
# 查看文件内容并分页
tail 文件名
# 查看文件内容并更新
tail -f 文件名 

查看文件夹

# 查看当前文件夹
pwd
# 查看当前文件夹下的文件
ls
# 查看当前文件夹下的文件
ll
# 查看当前文件夹下的文件
ls -l
# 查看当前文件夹下的文件
ls -al
# 查看当前文件夹下的文件
ls -ahl
# 查看当前文件夹下的文件
ls -ahl --color=auto
# 查看当前文件夹下的文件
ls -ahl --color=auto --group-directories-first

查看磁盘

# 查看磁盘使用情况
df -h
# 查看磁盘使用情况
df -hl
# 查看磁盘使用情况
df -hl --total
# 查看磁盘使用情况
df -hl --total --block-size=GB
# 查看磁盘使用情况
df -hl --total --block-size=GB --exclude-type=tmpfs
# 查看磁盘使用情况
df -hl --total --block-size=GB --exclude-type=tmpfs --exclude-type=devtmpfs

查看内存

# 查看内存使用情况
free -h
# 查看内存使用情况
free -hl
# 查看内存使用情况
free -hl --total
# 查看内存使用情况
free -hl --total --mega

查看CPU

# 查看CPU使用情况
top
# 查看CPU使用情况
top -d 1
# 查看CPU使用情况
top -d 1 -n 1
# 查看CPU使用情况
top -d 1 -n 1 -p 进程号

查看指定文件夹(文件)大小

# 查看指定文件夹大小
du -h 文件夹名
# 查看指定文件夹大小
du -hl 文件夹名
# 查看指定文件夹大小
du -hl --max-depth=1 文件夹名
# 查看指定文件夹大小
du -hl --max-depth=1 --block-size=GB 文件夹名

查看系统版本

# 查看系统版本
cat /etc/issue
# 查看系统版本
cat /etc/redhat-release
# 查看系统版本
cat /etc/lsb-release
# 查看系统版本
cat /etc/os-release

常用配置文件

  1. 开机自启动 /etc/rc.local
  2. 网络配置 /etc/sysconfig/network-scripts/ifcfg-eth0
  3. 定时任务 /etc/crontab
  4. 系统变量 /etc/profile

centos 下服务管理

# 查看服务状态
systemctl status 服务名
# 启动服务
systemctl start 服务名
# 停止服务
systemctl stop 服务名
# 重启服务
systemctl restart 服务名
# 开机自启动
systemctl enable 服务名
# 开机不自启动
systemctl disable 服务名

centos 下防火墙管理

# 查看防火墙状态
systemctl status firewalld
# 启动防火墙
systemctl start firewalld
# 停止防火墙
systemctl stop firewalld
# 重启防火墙
systemctl restart firewalld
# 开机自启动
systemctl enable firewalld
# 开机不自启动
systemctl disable firewalld
# 查看防火墙规则
firewall-cmd --list-all
# 查看防火墙规则
firewall-cmd --list-all --zone=public
# 查看防火墙规则
firewall-cmd --list-all --zone=public --permanent
# 开放端口
firewall-cmd --zone=public --add-port=端口号/tcp --permanent
# 开放端口
firewall-cmd --zone=public --add-port=端口号/udp --permanent
# 删除端口
firewall-cmd --zone=public --remove-port=端口号/tcp --permanent
# 删除端口
firewall-cmd --zone=public --remove-port=端口号/udp --permanent
# 重启防火墙
firewall-cmd --reload
Last Updated 2023/10/21 15:45:55