Linux环境常用命令

环境下载

VirtualBox-7.0.0-153978-Win.exe
CentOS-7-x86_64-DVD-2009.iso

系统版本查看

  • 查看centos版本
    cat /etc/redhat-release
  • 查看当前系统是32位还是64位
    /usr/bin/getconf LONG_BIT

网络不通

虚拟机ping不通物理机(NetWork is unreachable,Could not resolve host)

  1. 查看本机网卡
    nmcli d
  2. 修改网卡(本机网卡名:enp0s3)的配置ONBOOT="yes"
    vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
  3. 重启网络服务
    systemctl restart network

端口号

  • 查看正在使用中的端口号
    netstat -aptn
  • 查看防火墙放开的端口
    firewall-cmd --list-ports
  • 放开指定端口
    firewall-cmd --zone=public --add-port=8080/tcp --permanent
  • 防火墙重新加载配置
    firewall-cmd --reload
  • 根据端口号查找进程信息
    netstat -tunpl|grep 3306

检查端口号是否开放

telnet 14.215.177.39 80

yum

切换默认yum源为阿里源

  1. 备份默认yum源
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-backups
  2. 下载阿里yum源
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  3. 清除全部缓存
    yum clean all
  4. 重新缓存yum
    yum makecache
  5. 更新yum库
    yum update -y
  6. 查看yum源仓库列表
    yum repolist

ifconfig命令不存在

  • 安装前先查找命令所在安装包
    yum search ifconfig
  • 安装找的安装包
    yum install -y net-tools.x86_64

在线下载

wget

  • 安装wget工具
    yum install -y wget
  • 使用wget下载rarlinux-x64-612.tar.gz到当前目录
    wget https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz --no-check-certificate

curl

  • -o 下载,必须指定下载路径及下载文件名称
    curl -o rarlinux.tar.gz https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz

防火墙

# 查看防火墙状态
firewall-cmd --state

# 开启防火墙
systemctl start firewalld

# 开放端口(开放后需要要重启防火墙才生效)
firewall-cmd --zone=public --add-port=3306/tcp --permanent

# 重启防火墙
firewall-cmd --reload

# 查看已开放的端口
firewall-cmd --list-ports

# 关闭端口(关闭后需要要重启防火墙才生效)
firewall-cmd --zone=public --remove-port=3336/tcp --permanent

# 停止防火墙
systemctl stop firewalld

# 开机启动防火墙
systemctl enable firewalld

# 禁止防火墙开机启动
systemctl disable firewalld

压缩、解压缩

zip

# 安装zip解压工具
yum install -y unzip

# 命令示例:压缩文件
zip adele adele/
# 命令示例:压缩文件夹
zip -r adele adele/
# 命令示例:解压到当前目录
unzip adele.zip
# 命令示例:解压到指定目录
unzip adele.zip -d /home/sword/adele/

rar

# 安装rar解压工具
yum install -y wget
wget https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz --no-check-certificate
tar -zxvf rarlinux-x64-612.tar.gz -C /usr/local/
cd /usr/local/rar/
make

# 命令示例:压缩adele文件为adele.rar
rar a adele adele/
# 命令示例:压缩adele文件夹adele.rar
rar a -r adele adele/
# 命令示例:解压到当前目录
unrar x adele.rar
# 命令示例:解压到指定目录
unrar x adele.rar /home/sword/adele/

7z

参数含义:
a 压缩
x 解压缩
-o 是指定解压到的目录
-t 省略默认7z,可指定zip、7z、gzip、bzip2、tar等压缩类型。

# 安装7z解压工具
yum install -y epel-release
yum update -y
yum install  -y  p7zip

# 命令示例:压缩文件或文件夹
7za a adele adele/
# 命令示例:解压到当前目录
7za x adele.7z
# 命令示例:解压到指定目录
7za x adele.7z -o/home/sword/adele/
posted @ 2022-11-24 15:06  苇草剑  阅读(57)  评论(0)    收藏  举报