* rhel7的基本操作*

1、查看IP配置
[root@admin203 ~]# ls /etc/sysconfig/network-scripts/ifcfg-enp0s25
/etc/sysconfig/network-scripts/ifcfg-enp0s25
查看DNS配置
[root@admin203 ~]# cat /etc/resolv.conf

Generated by NetworkManager

nameserver 114.114.114.114
查看IP和主机绑定信息
[root@admin203 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
查看主机名
[root@admin203 ~]# cat /etc/hostname
admin203

2、关闭防火墙,设置开机不启动
查看状态
[root@admin203 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-09-11 09:47:40 CST; 1 day 5h ago
Main PID: 698 (firewalld)
CGroup: /system.slice/firewalld.service
└─698 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Sep 11 09:47:40 admin203 systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 11 09:47:40 admin203 systemd[1]: Started firewalld - dynamic firewall daemon.
关闭防火墙
[root@admin203 ~]# systemctl stop firewalld
开启防火墙
[root@admin203 ~]# systemctl start firewalld
开机自动启动防火墙
[root@admin203 ~]# systemctl enable firewalld
开机自动关闭防火墙
[root@admin203 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

3、临时和永久关闭selinux
查看selinux运行状态
[root@admin203 ~]# getenforce
Enforcing
临时关闭selinux,并查看运行状态
[root@admin203 ~]# setenforce 0
[root@admin203 ~]# getenforce
Permissive
临时开启selinux,并查看运行状态
[root@admin203 ~]# setenforce 1
[root@admin203 ~]# getenforce
Enforcing
永久关闭selinux,将enforcing改成disabled,保存重启即可
[root@admin203 ~]# vim /etc/selinux/config

This file controls the state of SELinux on the system.

SELINUX= can take one of these three values:

enforcing - SELinux security policy is enforced.

permissive - SELinux prints warnings instead of enforcing.

disabled - No SELinux policy is loaded.

SELINUX=disabled

SELINUXTYPE= can take one of three two values:

targeted - Targeted processes are protected,

minimum - Modification of targeted policy. Only selected processes are protected.

mls - Multi Level Security protection.

SELINUXTYPE=targeted

4、基本命令操作
用tty查看当前所属虚拟终端
[root@admin203 ~]# tty
/dev/pts/0
用type区分内外命令,语法:type 要检测的命令
[root@admin203 ~]# type cat
cat is hashed (/usr/bin/cat)
[root@admin203 ~]# type pwd
pwd is a shell builtin
查看所有shell类型
[root@admin203 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
查看一下/etc/passwd的每一行的最后一个字符
[root@admin203 ~]# head -1 /etc/passwd
root:x:0:0:root:/root:/bin/bash
查看当前目录下有哪些文件
[root@admin203 ~]# ls
anaconda-ks.cfg mima
[root@admin203 ~]# ls /etc/passwd
/etc/passwd
查看文件的详细信息,如创建时间,创建者,文件的读写权限
[root@admin203 ~]# ls -l /etc/passwd
-rw-r--r--. 1 root root 1118 Sep 11 22:24 /etc/passwd
Linux下快捷键总结
清屏:ctrl+L
退出: ctrl+D
搜素历史命令:ctr+R

查看硬件时间
[root@admin203 ~]# hwclock
Wed 12 Sep 2018 04:20:15 PM CST -0.875517 seconds
查看系统时间
[root@admin203 ~]# date
Wed Sep 12 16:20:44 CST 2018
修改时间
[root@admin203 ~]# date -s "2018-9-12 15:22:30"
Wed Sep 12 15:22:30 CST 2018
查看完整日期
[root@admin203 ~]# date "+%F"
2018-09-12
查看年份最后两位
[root@admin203 ~]# date "+%y"
18
查看时分秒
[root@admin203 ~]# date "+%M"
26
[root@admin203 ~]# date "+%H"
15
[root@admin203 ~]# date "+%S"
51
查看年月日
[root@admin203 ~]# date "+%Y-%m-%d"
2018-09-12
用time测量一个命令运行的时间
[root@admin203 ~]# time ls
anaconda-ks.cfg mima

real 0m0.002s
user 0m0.001s
sys 0m0.001s
帮助命令man,查看手册页或命令描述
语法:man 命令
[root@admin203 ~]# man cp
查看当前默认的运行级别
[root@admin203 ~]# systemctl get-default
multi-user.target
设置默认为第三启动级别
[root@admin203 ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
设置默认为第五启动级别
[root@admin203 ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.