2020-04-16

第一周

1、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。

  • slackware

    比较早的linux版本,遵循“KISS”(Keep It Simple, Stupid)原则,尽量保持系统的简洁,从而实现稳定、高效和安全

  • debian

    代表:ubuntu和deepin(深度)

    特点:更新升级比较快

  • redhat

    代表

    RHEL:企业版,收费,刚刚更新到8.0

    CentOS:社区版,兼容RHEL格式,免费,使用的最多

    中标麒麟:中国的linux系统,基于redhat,国家安全部门会使用

    Fedora:企业版(RHEL)的测试版本,免费,每6个月发行一个新版本

    特点:目前国内使用人群最多的Linux版本,稳定,但是更新比较慢

  • Archlinux

    轻量简洁,遵循K.I.S.S原则,用的不多

  • Gentoo

    极致性能,不提供传统意义的安装程序,下载源代码在本机上编译安装软件

  • LFS

    Linux From scratch 自制linux

  • Android

    kernel+busybox(工具集)+java虚拟机

2、安装Centos7.6操作系统,创建一个自己名字的用户名,并可以正常登录,将主要步骤截图。

  • 选择安装CentOS 7 64位操作系统

[图片上传失败...(image-f5739e-1587033305123)]

  • 设置硬盘大小为200G

[图片上传失败...(image-6408fa-1587033305123)]

  • 设置硬件参数

[图片上传失败...(image-873f50-1587033305123)]

  • 开始安装

[图片上传失败...(image-f652cf-1587033305123)]

  • 修改时区为"中国上海",软件包选择"GNOME Desktop"

[图片上传失败...(image-4da5f1-1587033305123)]

  • 磁盘选择标准分区

[图片上传失败...(image-14347a-1587033305123)]

  • 开始安装,设置root密码123456;创建scott用户,密码123456

[图片上传失败...(image-8efb09-1587033305123)]

3、配置环境变量,实现执行history的时候可以看到执行命令的时间。

命令:HISTTIMEFORMAT="%F %T "

%F是添加日期,%T是时间

命令行直接修改是临时生效,永久生效可以写到/etc/profile文件中

[root@centos7 ~]# HISTTIMEFORMAT="%F %T "
[root@centos7 ~]# history
 1  2020-04-15 15:56:13 ls
 2  2020-04-15 15:56:14 ll
 3  2020-04-15 15:56:20 cd /etc/
 4  2020-04-15 15:56:22 cd 
 5  2020-04-15 15:56:25 history
 6  2020-04-15 15:57:16 HISTTIMEFORMAT="%F %T "
 7  2020-04-15 15:57:17 history</pre>

4、总结Linux哲学思想。

  • 一切都是一个文件(包括硬件)

  • 小型/单一用途的程序

  • 链接程序,共同完成复杂的任务

  • 避免令人困惑的用户界面

  • 配置数据存储在文本中

5、总结Linux常用命令使用格式,并用实例说明。例如echo、screen、date、ifconfig、export等命令

  • echo

    功能:显示字符 语法:echo [-neE][字符串] 说明:echo会将输入的字符串送往标准输出。输出的字符串间以空白字符隔开, 并在最后加上换行号

    -E (默认)不支持 \ 解释功能 -n 不自动换行 -e 启用 \ 字符的解释功能

[root@centos7 ~]# echo \n
n
[root@centos7 ~]# echo "\n"
\n
[root@centos7 ~]# echo -e "\n"


[root@centos7 ~]# echo

[root@centos7 ~]# echo -n
[root@centos7 ~]# </pre>

  • screen

    CentOS7默认没有安装,需要使用yum安装

    • 创建新screen会话

      screen –S [SESSION]

    [root@centos7 ~]# screen -S xiaohong
    [detached from 94819.xiaohong]
    [root@centos7 ~]# screen -ls
    There is a screen on:
     94819.xiaohong  (Detached)
    1 Socket in /var/run/screen/S-root.
*   ##### **加入screen会话**

    screen –x [SESSION]

    前提:用相同用户登录到同一台机器时,才能加入

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n215" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># 加入叫“xiaohong”的screen
[root@centos7 ~]# screen -x xiaohong</pre>

*   ##### 退出并关闭screen会话

    exit

*   ##### 剥离当前screen会话

    Ctrl+a,d

    先按Ctrl+a,再按d,暂时退出,想要回到窗口可以使用screen -x或者-r

*   ##### 显示所有已经打开的screen会话

    screen -ls

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n286" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# screen -ls
    There is a screen on:
     95012.xiaohong  (Attached)
    1 Socket in /var/run/screen/S-root.</pre>

*   ##### 恢复某screen会话

    screen -r [SESSION]

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n289" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# screen -r xiaohong</pre>
  • date

    date 显示和设置系统时间

    格式:date [参数]... [+格式]

    参数:-u、-s、-d

    -u 显示GMT时间,GMT时间比Beijing时间早8小时

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n386" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# date
    Thu Apr 16 15:06:29 CST 2020
    [root@centos7 ~]# date -u
    Thu Apr 16 07:06:31 UTC 2020</pre>

    -s 根据字符串来设置日期与时间

    只有root权限才能执行

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n396" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># 设置日期为20200301,没有写时间默认是00:00:00
    [root@centos7 ~]# date -s 20200301
    Sun Mar 1 00:00:00 CST 2020

    设置时间为01:01:01

    [root@centos7 ~]# date -s 01:01:01
    Sun Mar 1 01:01:01 CST 2020

    同时设置日期和时间,以下几种写法都可以

    [root@centos7 ~]# date -s "20200305 03:03:03"
    Thu Mar 5 03:03:03 CST 2020
    [root@centos7 ~]# date -s "2020-03-06 03:03:03"
    Fri Mar 6 03:03:03 CST 2020
    [root@centos7 ~]# date -s "03:03:03 2020-03-07"
    Sat Mar 7 03:03:03 CST 2020
    [root@centos7 ~]# date -s "06:06:06 20200307"
    Sat Mar 7 06:06:06 CST 2020

    设置日期在2年以后

    [root@centos7 ~]# date -s '2 years'
    Sat Apr 16 15:23:45 CST 2022

    设置日期在2年以前

    [root@centos7 ~]# date -s '2 years ago'
    Thu Apr 16 15:23:54 CST 2020

    设置日期在5天之后

    [root@centos7 ~]# date -s '5 days'
    Thu Apr 23 15:24:08 CST 2020

    设置日期在5天以前

    [root@centos7 ~]# date -s '5 days ago'
    Sat Apr 11 15:26:19 CST 2020
    ​</pre>

    -d 显示字符串所指的日期与时间

    -d参数用的特别多,是个非常重要的参数,只是显示时间,不会修改当前时间

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n358" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># 显示两周后的日期
    [root@centos7 ~]# date -d '2 weeks'
    Thu Apr 30 15:17:08 CST 2020

    显示明天的日期

    [root@centos7 ~]# date -d 'next-day'
    Fri Apr 17 15:17:26 CST 2020
    [root@centos7 ~]# date -d 'tomorrow'
    Fri Apr 17 15:17:34 CST 2020

    显示昨天的日期

    [root@centos7 ~]# date -d last-day
    Wed Apr 15 15:17:43 CST 2020
    [root@centos7 ~]# date -d yesterday
    Wed Apr 15 15:17:55 CST 2020

    显示上个月的日期

    [root@centos7 ~]# date -d last-month
    Mon Mar 16 15:18:07 CST 2020

    显示下个月的日期

    [root@centos7 ~]# date -d next-month
    Sat May 16 15:18:11 CST 2020

    显示3天后的日期

    [root@centos7 ~]# date -d '3 days'
    Sun Apr 19 15:18:33 CST 2020

    显示3天前的日期

    [root@centos7 ~]# date -d '3 days ago'
    Mon Apr 13 15:18:36 CST 2020
    [root@centos7 ~]# date -d '-3 days'
    Mon Apr 13 15:18:50 CST 2020

    显示3年后的日期

    [root@centos7 ~]# date -d '3 years'
    Sun Apr 16 15:22:09 CST 2023

    显示3年前的日期

    [root@centos7 ~]# date -d '3 years ago'
    Sun Apr 16 15:22:12 CST 2017</pre>

    格式参数:

    %H : 小时(00..23)

    %M : 分钟(00..59)

    %s : 从 1970 年 1 月 1 日 00:00:00 UTC 到目前为止的秒数

    %S : 秒(00..61)

    %T : 直接显示时间 (24 小时制)

    %d : 日 (01..31)

    %m : 月份 (01..12)

    %Y : 完整年份 (0000..9999)

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n420" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># 显示当前时间
    [root@centos7 ~]# date '+%T'
    15:40:51

    显示当前日期

    [root@centos7 ~]# date '+%D'
    04/16/20

    通过显示年月日,自己DIY输出格式

    [root@centos7 ~]# date +%Y%m%d
    20200416
    [root@centos7 ~]# date +%Y-%m-%d
    2020-04-16
    [root@centos7 ~]# date -d '10 days ago' '+%Y-%m-%d'
    2020-04-06
    [root@centos7 ~]# date -d '10 days ago' '+%Y-%m-%d %H:%M:%S'
    2020-04-06 15:43:17</pre>

  • ifconfig

    作用:命令用于显示或设置网络设备,可设置网络设备的状态,或是显示目前的设置。

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n451" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# ifconfig
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.100.139 netmask 255.255.255.0 broadcast 192.168.100.255
    inet6 fe80::4661:5cfd:9c5:bb07 prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:b3:a9:51 txqueuelen 1000 (Ethernet)
    RX packets 48927 bytes 10496398 (10.0 MiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 26017 bytes 3914777 (3.7 MiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    inet 127.0.0.1 netmask 255.0.0.0
    inet6 ::1 prefixlen 128 scopeid 0x10<host>
    loop txqueuelen 1000 (Local Loopback)
    RX packets 1037 bytes 117943 (115.1 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1037 bytes 117943 (115.1 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</pre>

    启动关闭指定网卡

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n454" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# ifconfig ens33 down
    [root@centos7 ~]# ifconfig ens33 up</pre>

    给指定网卡配置ip地址

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n458" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># 给ens33网卡配置ip地址
    [root@centos7 ~]# ifconfig ens33 192.168.100.139

    配置ip地址,并加上子网掩码

    [root@centos7 ~]# ifconfig ens33 192.168.100.139 netmask 255.255.255.0

    配置ip地址,子网掩码,广播地址

    [root@centos7 ~]# ifconfig ens33 192.168.100.139 netmask 255.255.255.0 broadcast 192.168.100.255</pre>

    启用和关闭ARP协议

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n465" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# ifconfig ens33 arp
    [root@centos7 ~]# ifconfig ens33 -arp</pre>

    设置MTU

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n470" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# ifconfig ens33 mtu 1600
    [root@centos7 ~]# ifconfig
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1600
    inet 192.168.100.139 netmask 255.255.255.0 broadcast 192.168.100.255
    inet6 fe80::4661:5cfd:9c5:bb07 prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:b3:a9:51 txqueuelen 1000 (Ethernet)
    RX packets 49649 bytes 10555969 (10.0 MiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 26449 bytes 3963159 (3.7 MiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</pre>

  • export

    作用:用于设置或显示环境变量

    语法:export[-fnp][变量名称]=[变量设置值]

    参数说明

    • -f  代表[变量名称]中为函数名称。

    • -n  删除指定的变量。变量实际上并未删除,只是不会输出到后续指令的执行环境中。

    • -p  列出所有的shell赋予程序的环境变量

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n507" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# export -p
    declare -x DISPLAY="localhost:12.0"
    declare -x HISTCONTROL="ignoredups"
    declare -x HISTSIZE="1000"
    declare -x HOME="/root"
    declare -x HOSTNAME="centos7.0"
    declare -x LANG="en_US.UTF-8"
    declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
    declare -x LOGNAME="root"
    ​</pre>

    定义环境变量并赋值

    <pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="bash" cid="n513" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@centos7 ~]# export ABC=1
    [root@centos7 ~]# export -p
    declare -x ABC="1"
    declare -x DISPLAY="localhost:12.0"
    declare -x HISTCONTROL="ignoredups"
    declare -x HISTSIZE="1000"
    declare -x HOME="/root"
    declare -x HOSTNAME="centos7.0"
    declare -x LANG="en_US.UTF-8"
    declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
    declare -x LOGNAME="root"
    ​</pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容