Linux根下目录详解

1. [root@oldboy60service01 ~]# tree -L 1 /

/
├── alex
├── bin -> usr/bin 二进制文件,命令
├── boot 引导系统启动,引导程序和系统内核
├── dev 存放设备文件(光盘,U盘,硬盘分区...)
├── etc 存放系统配置文件
├── home 普通用户家目录
├── lib -> usr/lib 库文件(系统正常运行需要的文件)
├── lib64 -> usr/lib64 64位文件
├── media 媒体文件(以前是挂载光盘)
├── mnt 临时挂载目录(给设备开个入口,例如光盘有了入口打开访问)
├── opt 第三方软件安装目录
├── proc 内存信息里的进程信息(虚拟目录)
├── root超级用户家目录
├── run
├── sbin -> usr/sbin root用户使用的命令
├── srv
├── sys
├── tmp 临时的目录(垃圾堆)
├── usr 存放用户软件、命令
├── var 经常变化的内容(日志)
└── zhang

21 directories, 0 files
[root@oldboy60service01 ~]#

2.Linux下面的设备必须要有挂载才能使用

mount /dev/cdrom /mnt/
挂载 给光盘 设置了个入口叫/mnt

[root@oldboy60service01 dev]# cd cdrom
-bash: cd: cdrom: Not a directory
[root@oldboy60service01 dev]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboy60service01 dev]# ls /mnt
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL

3. /etc 目录

1.网卡配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0
/系统配置文件/system configure/网络-脚本(管理网卡命令)/

[root@oldboy60service01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet   网卡类型 以太网
PROXY_METHOD=none  
BROWSER_ONLY=no
BOOTPROTO=none  网卡获取 i p 的方式  none/static 手动设置(固定)
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0  网卡名称
UUID=99bf4e92-6687-47ce-85be-1a6e95963074  设备标识符
DEVICE=eth0  设备名称
ONBOOT=yes  网卡是否开机自启动
IPADDR=10.0.0.200   i p 地址
PREFIX=24  子网掩码
GATEWAY=10.0.0.254  默认网关(大楼的大门)
DNS1=10.0.0.254  域名解析
IPV6_PRIVACY=no
[root@oldboy60service01 ~]# 

systemctl restart network 重启网卡

  1. /etc/resolv.conf 配置DNS
[root@oldboy60service01 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 10.0.0.254

/etc/resolv.conf 实时生效(重启网络后,网卡配置覆盖)
主要修改的是网卡配置文件中的即可

  1. /etc/hostname 配置主机名
[root@oldboy60service01 ~]# hostname 显示当前主机名
oldboy60service01
[root@oldboy60service01 ~]# hostname oldboy60zhang更改主机名
[root@oldboy60service01 ~]# hostname
oldboy60zhang

hostname命令(临时的,重启系统之后失效)

[root@oldboy60service01 ~]# vi /etc/hostname
oldboy60service01
~                                                                                                                                                                         
~                                                                                            
~                                                                                            
"/etc/hostname" 1L, 18C

更改永久主机名,修改 vi /etc/hostname 里的内容
Centos7改主机名命令:hostnamectl set-hostname oldboy60zhang

  1. /etc/hosts 主机名与IP地址对应关系(搭建测试环境)
[root@oldboy60service01 ~]# vim /etc/hosts
[root@oldboy60service01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.200  oldboy60service001
[root@oldboy60service01 ~]# ping oldboy60service001
PING oldboy60service001 (10.0.0.200) 56(84) bytes of data.
64 bytes from oldboy60service001 (10.0.0.200): icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from oldboy60service001 (10.0.0.200): icmp_seq=5 ttl=64 time=0.272 ms
^C
--- oldboy60service001 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0.107/0.189/0.272/0.069 ms
[root@oldboy60service01 ~]# 
  1. /etc/profile 用来配置环境变量
36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=10.0.0.1 50827 10.0.0.200 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env
[root@oldboy60service01 ~]#  

(1)系统创建好的,我们可以随便使用的。存放系统信息
系统环境变量的特点都是大写的,例:PWD、LANG...

(2)PATH 路径(存放的是系统命令的位置),配合echo使用
显示变量里的内容echo $PATH

[root@oldboy60service01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@oldboy60service01 ~]#
使用:分开每一个文件
/usr/local/sbin
/usr/local/bin
/usr/sbin === /sbin
/usr/bin ===/bin
/root/bin 默认是不存在的

PATH=/bin修改变量内容
[root@oldboy60service01 ~]# PATH=/bin
[root@oldboy60service01 ~]# echo $PATH
/bin
[root@oldboy60service01 ~]#
断开后重新连接,变量失效

  1. /etc/bashrc 别名
    alias 显示系统里所有的别名
[root@oldboy60service01 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
[root@oldboy60service01 ~]# 

/etc 国法
/etc/profile
/etc/bashrc
家规,以 . (点) 开头的文件是隐藏文件
~/.bash_profile
~/.bashrc

[root@oldboy60service01 ~]# ll
total 4
-rw-------. 1 root root 1507 Mar 26 15:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root   24 Apr  7 19:15 oldboy
[root@oldboy60service01 ~]# ls -la
total 32
dr-xr-x---.  3 root root  165 Apr  8 17:50 .
dr-xr-xr-x. 19 root root  249 Apr  7 17:27 ..
-rw-------.  1 root root 1507 Mar 26 15:37 anaconda-ks.cfg
-rw-------.  1 root root 1651 Apr  7 23:20 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
drwxr-xr-x.  2 root root   24 Apr  7 19:15 oldboy
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
-rw-------.  1 root root  623 Apr  8 17:50 .viminfo
[root@oldboy60service01 ~]# 
  1. /etc/inittab 运行级别的配置文件
    (1). CentOS 6服务器不同状态
    runlevel
    0 关机状态
    1 单用户模式(没有网络,用来重新设置root密码)
    2 多用户模式 (没有NFS)
    3 完全多用户模式 文本模式 命令行模式
    4 没有使用
    5 图形化界面模式 桌面模式 X11
    6 重启

(2). CentOS 7服务器不同状态
target
0 poweroff.target 关机
1 rescue.target 救援模式
2 multi-usr 多用户模式
3 multi-usr 多用户模式
4 multi-usr 多用户模式
5 graphical 图形模式
6 reboot 重启

[root@oldboy60service01 ~]# ls -l /usr/lib/systemd/system/runlevel*.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel1.target -> rescue.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel5.target -> graphical.target
Mar 26 15:32 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[root@oldboy60service01 ~]# 

(3). 如何修改运行级别:
命令systemctl set-default
systemctl set-default graphical.target

[root@oldboy60service01 ~]# 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.
[root@oldboy60service01 ~]# 

(4). 查看运行级别
命令systemctl get-default
systemctl get-default

[root@oldboy60service01 ~]# systemctl get-default 
multi-user.target
[root@oldboy60service01 ~]# 
  1. /etc/fstab 开机自动挂载的列表
[root@oldboy60service01 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Mar 26 15:31:31 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=4dad89b5-9401-42d9-9685-0d9093647979 /                       xfs     defaults        0 0
UUID=de6cdbf0-7d5a-475a-bb51-cde7e0627e06 /boot                   xfs     defaults        0 0
UUID=0354a10b-4471-4fd4-94ff-d8d802206a31 swap                    swap    defaults        0 0
  1. /etc/rc.local(完整路径 /etc/rc.d/rc.local)开机运行的命令脚本

在CentOS 6中随便可以写
但是在CentOS 7中需要先配置,使用命令chmod +x(只需要配置一次)

[root@oldboy60service01 ~]# ls -l /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Oct 31 07:31 /etc/rc.d/rc.local
[root@oldboy60service01 ~]# chmod +x /etc/rc.d/rc.local
[root@oldboy60service01 ~]# ls -l /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 473 Oct 31 07:31 */etc/rc.d/rc.local*
[root@oldboy60service01 ~]# vim /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
reboot
~                                                                                                          
~                                                                                                          
~                  
  1. /etc/init.d

在CentOS 6中用来存放服务器管理命令(脚本)

[root@oldboy60service01 ~]# ls -l /etc/init.d/
total 40
-rw-r--r--. 1 root root 18281 Aug 24  2018 functions
-rwxr-xr-x. 1 root root  4569 Aug 24  2018 netconsole
-rwxr-xr-x. 1 root root  7923 Aug 24  2018 *network*
-rw-r--r--. 1 root root  1160 Oct 31 07:31 README

在CentOS 7中是一个目录
/usr/lib/systemd/system

-rw-r--r--. 1 root root  365 Oct 31 07:03 wpa_supplicant.service
[root@oldboy60service01 ~]# ls -l /usr/lib/systemd/system/network*
-rw-r--r--. 1 root root 464 Oct 31 07:31 /usr/lib/systemd/system/network-online.target
-rw-r--r--. 1 root root 461 Oct 31 07:31 /usr/lib/systemd/system/network-pre.target
-rw-r--r--. 1 root root 480 Oct 31 07:31 /usr/lib/systemd/system/network.target
[root@oldboy60service01 ~]#
  1. /etc/motd 会在用户登录系统之后显示
[root@oldboy60service01 ~]# cat /etc/motd
佛祖保佑,永无BUG
[root@oldboy60service01 ~]# 
  1. /etc/issue 会在用户登录系统之前显示
[root@oldboy60service01 ~]# >/etc/issue
[root@oldboy60service01 ~]# cat /etc/issue
[root@oldboy60service01 ~]# cat /etc/issue.net
\S
Kernel \r on an \m
[root@oldboy60service01 ~]# echo oldboy >/etc/issue.net
[root@oldboy60service01 ~]# cat /etc/issue.net
oldboy
[root@oldboy60service01 ~]# 

(>)大于号的作用就是:先清空文件内容,再把信息写入进去

4. /usr(user或unix software resource)用户数据

/ 下的和 /usr 下的目录类似

[root@oldboy60service01 ~]# tree -L 1 / /usr/
/
├── alex
├── bin -> usr/bin
├── boot
├── dev
├── etc
├── home
├── lib -> usr/lib
├── lib64 -> usr/lib64
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin -> usr/sbin
├── srv
├── sys
├── tmp
├── usr
├── var
└── zhang
/usr/
├── bin
├── etc
├── games
├── include
├── lib
├── lib64
├── libexec
├── local
├── sbin
├── share
├── src
└── tmp -> ../var/tmp

33 directories, 0 files
[root@oldboy60service01 ~]# 

/usr/local(编译安装的软件)

备菜( ./configure), 炒菜(make), 上菜(make install)

LInux下面常见的安装软件方式

yum (yum install -y) 自动下载安装
rpm 大型软件需要自己解决依赖关系,自己安装
编译安装:自己下载,自己安装

rpm -ivh

-i 安装 -v显示 -h以人类可读形式显示

rpm -qa 查询软件是否安装

[root@oldboy60service01 dev]# rpm -qa yum
yum-3.4.3-161.el7.centos.noarch
[root@oldboy60service01 dev]# 

rpm -ql telnet(查看软件包)

[root@oldboy60service01 dev]# rpm -ql yum
/usr/share/locale/cs/LC_MESSAGES/yum.mo
/usr/share/locale/da/LC_MESSAGES/yum.mo
/usr/share/locale/de/LC_MESSAGES/yum.mo
/usr/share/locale/el/LC_MESSAGES/yum.mo
/usr/share/locale/nl/LC_MESSAGES/yum.mo
/var/lib/yum/yumdb
[root@oldboy60service01 dev]# 

5. /var系统日志

(1). /var/log

(2). /var/messages服务和系统信息

(3). /var/secure用户登录信息

Failed password用户登录系统密码错误

6. /proc

(1). /proc/cpuinfo CPU信息

[root@oldboy60service01 ~]# cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping    : 9
microcode   : 0x70
cpu MHz     : 2712.000
cache size  : 3072 KB
physical id : 0
siblings    : 1
core id     : 0

processor : 3 表示第4个核心(0 表示第一个核心)
physical id : 1 表示第2个CPU

[root@oldboy60service01 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1  CPU核心
On-line CPU(s) list:   0  CPU编号
Thread(s) per core:    1
Core(s) per socket:    1  实际物理CPU个数(专业叫  “几”  路)
Socket(s):             1  物理接口
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 142
Model name:            Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Stepping:              9
CPU MHz:               2712.000
CPU max MHz:           0.0000
CPU min MHz:           0.0000
BogoMIPS:              5424.00
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0
Flags:                 fpu vme de pse tsc msr pae 
[root@oldboy60service01 ~]# 

CPU(s) : 表示CPU核心
Socket(s ) : 表示物理接口

(2). /proc/meminfo 内存信息

[root@oldboy60service01 ~]# cat /proc/meminfo
MemTotal:         995896 kB
MemFree:          715736 kB
MemAvailable:     696088 kB
Buffers:            2076 kB
Cached:            89472 kB
SwapCached:            0 kB
[root@oldboy60service01 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           972M        130M        698M        7.7M        143M        679M
Swap:          1.0G          0B        1.0G

以人类可读的形式显示 free -h 命令

[root@oldboy60service01 ~]# free 
              total        used        free      shared  buff/cache   available
Mem:         995896      133292      715492        7836      147112      695856
Swap:       1048572           0     1048572

(3). /proc/loadavg平均负载,衡量系统繁忙程度指标

[root@oldboy60service01 ~]# cat /proc/loadavg
0.00 0.01 0.05 2/115 7726
[root@oldboy60service01 ~]# 

0.00 表示1分钟内的负载数
0.01表示5分钟内的负载数
0.05表示15分钟内的负载数

[root@oldboy60service01 ~]# w
 22:58:23 up 58 min,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      22:00   57:59   0.03s  0.03s -bash
root     pts/0    10.0.0.1         22:00    7.00s  0.08s  0.03s w

w 命令能显示负载数

[root@oldboy60service01 ~]# uptime
 23:01:22 up  1:01,  2 users,  load average: 0.07, 0.03, 0.05

uptime === w 命令的第一行

如果负载接近于系统核心总数的时候表示忙

(4). /proc/mounts系统挂载信息

[root@oldboy60service01 ~]# cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,seclabel,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0

7.Linux启动流程

(1).CentOS 6启动流程
按下电源——开机自检(BIOS)——MBR引导——GRUB菜单(选择不同内核,单用户模式)——加载内核(/boot加载到内存)——运行INIT进程———
读取/etc/inittab——读取/etc/rc.sysinit初始化系统——根据运行级别运行/etc/rc数字.d下面的脚步/服务——启动mingetty显示登录界面,运行login明哥tty

CentOS 6串行运行

(2).CentOS 7启动流程
按下电源——开机自检(BIOS)——MBR引导——GRUB菜单(救援模式)——加载内核(systemd,/etc/systemd/system/default.target读取运行级别,/usr/lib/systemd/system/sysinit.target初始化系统,并行.启动服务,/usr/lib/systemd/system/getty.target显示login界面)

CentOS 7并行运行

你可能感兴趣的:(Linux根下目录详解)