centos7系统常用命令使用整理

在安装centos7的时候我一般都是最小安装,很多软件可能都没有带,如果是选择带桌面版本的话 多数常用命令都在的。

我一般首次登录后我就会替换yum的源,国内清华源,科大源,网易,阿里云源都不错,我个人喜欢使用阿里云源

#备份原来的yum源,其实这一步问题不大,基本上不会出错,备份只为了安全
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

#下载阿里云的CentOS-Base.repo 到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#添加EPEL,这个是扩展源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#清理缓存并生成新的缓存
yum clean all #新系统其实是没有缓存的
yum makecache

有的时候会发现没有wget,没有ifconfig 这个时候可以安装一个网络工具包

yum install -y net-tools

防火墙相关的命令

# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop
#查看防火墙状态
systemctl status firewalld
或
firewall-cmd --state
#查看防火墙规则
firewall-cmd --list-all
# 查询端口是否开放
firewall-cmd --query-port=69/UDP
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

在执行防火墙的一些命令时候发现命令参数不能自动识别,可以安装以下工具

yum install bash-completion #需重启生效

还有一个时间显示,我个人比较喜欢

修改:vim /etc/bashrc

[ "$PS1" = "\s-\v\$ " ] && PS1="[u@h W]\$ ";

查看内核版本

cat /proc/version
rpm -q centos-release

yum方式软件安装与卸载

#安装
yum install -y net-tools
#卸载
yum remove -y net-tools
#也可以卸载一组
yum remove -y mariadb*
原文地址:https://www.cnblogs.com/life512/p/13266618.html