Linux_Study


作者:冰红茶

参考书籍:《鸟哥的Linux私房菜》 第三版 鸟哥


想想自己以后多半在Linux环境中摸爬滚打了,学习Linux的基本操作必不可少。半年前我学了一半,但是由于一些原因中断了学习。后来学C和Node.js等后端语言的时候,明显感受到shell命令行和Linux环境对于开发的重要性。所以后面打算再补四章的内容:script和软件安装,进程与程序管理和Linux中常见的网络命令^_ ^

目录

一、计算机系统与Linux

1.1 计算机系统

1.2 Linux是什么

1.3 Linux如何学习

二、 主机规划与磁盘分区

2.1 各种硬件设备在Linux中的文件名

2.2 磁盘分区与组成

2.3 开机流程与主引导分区(MBR)

三、 首次登陆和在线求助man page

3.1 首次登陆系统

3.2 超简单的文本编辑器:nano

3.3 正确的开关机

四、 文件权限和目录配置

4.1 文件权限的概念

4.2 改变文件的属性和权限

4.3 目录与文件的权限意义

4.4 Linux的目录配置

五、 Linux文件与目录管理

5.1 目录的相关操作

5.2 关于执行文件路径的变量:$PATH

5.3 文件内容查阅

5.4 修改文件时间或创建新文件:touch

5.5 文件的默认权限与隐藏属性与特殊权限

5.6 命令和文件的查询

六、 Linux磁盘与文件系统的管理

6.1 EXT2文件系统

6.2 注意

6.3 相关命令

6.4 目录树与其他文件系统

6.5 文件系统的简单操作

6.6 磁盘的分区,格式化,检验和挂载

七、 文件与文件系统的压缩与打包

7.1 常见的压缩命令

7.2 完整的备份工具dump和恢复工具restore

八、 vim程序编辑工具

8.1 vi与vim

8.2 一些常用的命令

8.3 Vim的文件保存,恢复与打开时的警告信息

8.4 其他操作与语系转换

九、 bash

9.1 硬件,内核,shell和bash的关系

9.2 shell的变量功能

9.3 Bash shell的操作环境

9.4 Bash shell的环境配置文件(太复杂了,不看)

9.5 数据的重定向

9.6 命令与管道命令

十、 正则表达式

10.1 基础正则表达式

10.2 拓展正则表达式

10.3 sed工具

10.4 格式化打印:printf

10.5 awk:好用的数据处理工具

10.6 文件比较工具

十一、 Shell Script

11.1 基础知识

11.2 条件判断式

11.3 循环

11.4 函数function

11.5 调试

十二、 软件安装

12.1 make和configure

12.2 软件管理器RPM、RPMS和YUM

十三、 进程与程序管理

13.1 进程与程序

13.2 工作管理

13.3 系统资源的查看

十四、 Linux中常见的网络命令

14.1 设置网络参数的命令

14.2 工作管理

14.3 系统资源的查看


一、计算机系统与Linux

1.1 计算机系统

1) 五大单元

2) 存储单位

3) CPU

4) 北桥VS南桥

5) 外频VS倍频

6) 内存Memory

7) 操作系统

1.2 Linux是什么

1) Linux是一套操作系统

1.3 Linux如何学习

1) Linux有两种界面

分别是图形界面X Window和命令行界面Common Line,X Window System也只是运行在Linux上的一套软件。

2) 基础知识:

3) CentOS7.2 设置GRUB2引导界面分辨率

    [root\@min-base \~]\# vim /etc/default/grub

将GRUB_TERMINAL_OUTPUT值由默认的”console”改为”gfxterm”,并添加GRUB_GFXMODE

    GRUB_TIMEOUT=2

    GRUB_DISTRIBUTOR="$(sed 's, release .\*$,,g' /etc/system-release)"

    GRUB_DEFAULT=saved

    GRUB_DISABLE_SUBMENU=true

    GRUB_TERMINAL_OUTPUT="gfxterm"

    GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap
    rhgb quiet"

    GRUB_DISABLE_RECOVERY="true"

    GRUB_GFXMODE=1440x900,1024x768,640x480

4) 修改命令行颜色

            [root@MiWiFi-R3-srv software]# echo $PS1
            //当前用户的账号名称\@主机名的第一个名字工作目录的最后一层目录名
            [\u@\h \W]$

PS1的常用参数以及含义:

PS1的常用参数 含义
\d 代表日期,格式为weekday month date,例如:”Mon Aug 1”
\H 完整的主机名称
\h 仅取主机名中的第一个名字
\t 显示时间为24小时格式,如:HH:MM:SS
\T 显示时间为12小时格式
\A 显示时间为24小时格式:HH:MM
\u 当前用户的账号名称
\v BASH的版本信息
\w 完整的工作目录名称
\W 利用basename取得工作目录名称,只显示最后一个目录名
\# 下达的第几个命令
\$ 提示字符,如果是root用户,提示符为\# ,普通用户则为 \$
F B 颜色
F B 颜色
30 40 黑色
31 41 红色
32 42 绿色
33 43 黄色
34 44 蓝色
35 45 紫红色
36 46 青蓝色
37 47 白色
            # PS1='[\[\e[32;40m\]\u@\h \w \t]$ \[\e[0m\]'
            PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\$ "
            # cd
            # ls -la
            # vim .bashrc
            PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\$ "
            # source .bashrc

二、 主机规划与磁盘分区

2.1 各种硬件设备在Linux中的文件名

1) 各种硬件设备在Linux中的文件名

设备 设备在Linux内的文件名
IDE硬盘 /dev/hd[a-d]
SCSI/SATA/USB /dev/sd[a-p]
软驱 /dev/fd[a-p]
打印机 25针:/dev/lp[0-2] USB:/dev/usb/lp[0-15]
鼠标 USB:/dev/usb/mouse[0-15] PS2:/dev/psaux
当前的CD ROM/DVD ROM /dev/cdrom
当前鼠标 /dev/mouse
磁带机 IDE:/dev/ht0 SCSI:/dev/st0

2.2 磁盘分区与组成

1) IDE硬盘

IDE/Jumping Master Slave
IDE1(Primary) /dev/hda /dev/hdb
IDE2(Secondary) /dev/hdc /dev/hdd

2) SCSI/SATA/USB

3) 磁盘的组成

设备 设备在Linux内的文件名
P1 /dev/hda1
P2 /dev/hda2
P3 /dev/hda3
P4 /dev/hda4

2.3 开机流程与主引导分区(MBR)


三、 首次登陆和在线求助man page

3.1 首次登陆系统

1) 窗口模式和命令行模式的切换

2) 命令格式

            [lvhongbin@loccalhost ~]$ command [-option] parameter1 parameter2 …
            账号名                     命令  选项  参数1     参数二

3) Linux是区分大小写的;

4) 重要的热键

快捷键 含义
【Tab】【Tab】 具有“命令补全”和“文件补齐”的功能;
【Ctrl】+ c 强制当前程序“停止”;
【Ctrl】+ d 关闭文字界面;
man命令 按下空格键进行往下翻页,按下“q”离开man环境
info命令 可以按下N、P、U分别进行下一个,上一个和上一个节点的选择,光标选中开头具有“*”命令的一行并按下【ENTER】便可进入该节点,?号显示命令一览表

3.2 超简单的文本编辑器:nano

3.3 正确的开关机

1) 注意

            [root@MiWiFi-R3-srv software]# netstat -a
            Active Internet connections (servers and established)
            Proto Recv-Q Send-Q Local Address           Foreign Address         State      
            tcp        0      0 0.0.0.0:sunrpc          0.0.0.0:*               LISTEN     
            tcp        0      0 MiWiFi-R3-srv:domain    0.0.0.0:*               LISTEN     
            tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
            tcp        0      0 localhost:ipp           0.0.0.0:*               LISTEN     
            tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN     
            tcp6       0      0 [::]:sunrpc             [::]:*                  LISTEN     
            tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
            tcp6       0      0 localhost:ipp           [::]:*                  LISTEN     
            tcp6       0      0 localhost:smtp          [::]:*                  LISTEN     
            udp        0      0 0.0.0.0:51977           0.0.0.0:*                          
            udp        0      0 0.0.0.0:54043           0.0.0.0:*                          
            udp        0      0 0.0.0.0:mdns            0.0.0.0:*                          
            udp        0      0 MiWiFi-R3-srv:domain    0.0.0.0:*                          
            udp        0      0 0.0.0.0:bootps          0.0.0.0:*                          
            udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                          
            udp        0      0 localhost:323           0.0.0.0:*                          
            udp6       0      0 [::]:49660              [::]:*                             
            udp6       0      0 localhost:323           [::]:*                             
            raw6       0      0 [::]:ipv6-icmp          [::]:*                  7          
            Active UNIX domain sockets (servers and established)
            Proto RefCnt Flags       Type       State         I-Node   Path
            unix  2      [ ACC ]     STREAM     LISTENING     16128    /var/run/rpcbind.sock
            unix  2      [ ACC ]     STREAM     LISTENING     13569    /run/lvm/lvmetad.socket
            unix  2      [ ACC ]     STREAM     LISTENING     16132    /var/run/libvirt/virtlogd-sock
            unix  2      [ ACC ]     STREAM     LISTENING     36700    @/tmp/dbus-10iqxiu4
  • 如果要看后台执行的程序,可以执行“ps -aux”的命令;
            [root@MiWiFi-R3-srv software]# ps -aux
            USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
            root          1  0.0  0.1 193744  6888 ?        Ss   May26   0:16 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
            root          2  0.0  0.0      0     0 ?        S    May26   0:00 [kthreadd]
            root          3  0.0  0.0      0     0 ?        S    May26   0:00 [ksoftirqd/0]
            root          5  0.0  0.0      0     0 ?        S<   May26   0:00 [kworker/0:0H]
            root          7  0.0  0.0      0     0 ?        S    May26   0:00 [migration/0]
            root          8  0.0  0.0      0     0 ?        S    May26   0:00 [rcu_bh]
            root          9  0.0  0.0      0     0 ?        R    May26   0:07 [rcu_sched]
            root         10  0.0  0.0      0     0 ?        S    May26   0:00 [watchdog/0]
            root         11  0.0  0.0      0     0 ?        S    May26   0:00 [watchdog/1]
            root         12  0.0  0.0      0     0 ?        S    May26   0:00 [migration/1]
            root         13  0.0  0.0      0     0 ?        S    May26   0:00 [ksoftirqd/1]

2) 数据同步写入磁盘:sync

3) 常用的关机命令:shutdown

参数 参数说明
[-t] 在改变到其它runlevel之前﹐告诉init多久以后关机。
[-r] 重启计算器。
[-k] 并不真正关机﹐只是送警告信号给每位登录者〔login〕。
[-h] 关机后关闭电源〔halt〕。
[-n] 不用init﹐而是自己来关机。不鼓励使用这个选项﹐而且该选项所产生的后果往往不总是你所预期得到的。
[-c] cancel current> - process取消目前正在执行的关机程序。所以这个选项当然没有时间参数﹐但是可以输入一个用来解释的讯息﹐而这信息将会送到每位使用者。
[-f] 在重启计算器〔reboot〕时忽略fsck。
[-F] 在重启计算器〔reboot〕时强迫fsck。
[-time] 设定关机〔shutdown〕前的时间。
            /sbin/shutdown -h now-----立即关机;
            /sbin/shutdown -h 20:49----20:49分关机
            /sbin/shutdown -h +10-----10分钟后关机
            /sbin/shutdown -r now -----立即重启
            /sbin/shutdown -r +10 ‘The system will> - reboot'----10分钟后系统重启并给每个登录用户发通知
            /sbin/shutdown -k now ‘The system will> - reboot'----仅给每个登录用户发通知并不真关机

4) halt 最简单的关机命令

5) reboot

6) 切换执行等级:init

7) Poweroff


四、 文件权限和目录配置

4.1 文件权限的概念

            -rw-rw-r--.  1      lvhongbin   lvhongbin   17      Dec 31 17:20    hello.txt
            文件权限    连接数 所有者     用户组 文件大小 最后修改的日期    文件名
参数 参数说明
group1:目录,文件或者链接文件
[d] 表示目录
[-] 表示文件
[|] 表示连接文件linkfile
[b] 表示设备文件里面的可供存储的接口设备
[c] 表示设备文件里面的串行端口设备,如鼠标和键盘
group2 文件所有者的权限
[r] 表示可读
[w] 表示可写
[x] 表示可执行
[-] 表示啥权利都没有>《<
group3 同用户组的权限
[r] 表示可读
[w] 表示可写
[x] 表示可执行
[-] 表示啥权利都没有>《<
group4 其他非本用户组的权限
[r] 表示可读
[w] 表示可写
[x] 表示可执行
[-] 表示啥权利都没有>《<

4.2 改变文件的属性和权限

1) chgrp改变文件所属用户组

2) chown改变文件所有者

3) chmod改变文件的权限

            格式:chmod [-r] xyz 文件名/文件目录
chmod u g o a +(加入) -(除去) =(设置) r w x 文件或者目录
            // 注意,以上u=rwx,go=rx的逗号旁边是没有空格隔开的
            [root@MiWiFi-R3-srv software]# chmod u=rwx,go=rx hello.txt

4) cp复制

4.3 目录与文件的权限意义

1) 权限对文件的重要性

2) 权限对目录的重要性;

3) 重要的命令:

4.4 Linux的目录配置

1) Filesystem hierarchy standard, FHS目录配置标准

可分享的shareable 不可分享的unshareable
不变的static /usr软件放置处 /etc配置文件
/opt第三方软件 /boot开机与内核文件
可变动的variable /var/mail用户邮件信箱 /var/run程序相关
/var/spool/news新闻组 /var/lock程序相关
目录 内容
/bin 系统执行文件
/boot 开机会使用到的文件
/dev 任何设备和接口设备的文件
/etc 系统的主要配置文件,如人员的账号密码
/home 系统默认用户的主文件夹
/lib 系统的函数库
/media 可删除的设备,包括DVD,软盘等
/mnt 暂时挂载某些设备
/opt 第三方软件放置的目录,如KDE这个桌面管理系统
/root 系统管理员的主文件夹
/sbin 包括开机,修复,还原系统所需要的重要系统执行命令
/srv 跟网络服务有关
/tmp 程序运行时数据暂时放置的地方

2) 绝对路径VS相对路径


五、 Linux文件与目录管理

5.1 目录的相关操作

5.2 目关于执行文件路径的变量:$PATH

            PATH=”$PATH”:/root

5.3 文件内容查阅

> - cat:concatenate由第一行开始显示文件内容;

5.4 修改文件时间或创建新文件:touch

            ls -l --time=atime 文件全路径
            // “ll”两个小写的l表示“ls
            // -l”的命令,命令与命令之间用分号;隔开。默认查询修改时间mtime,此时间不需要添加--time命令,否则会出错;
            ll test.txt; ll --time=ctime test.txt; ll --time=atime test.txt
            touch -d "2 days ago" test.txt

5.5 文件的默认权限与隐藏属性与特殊权限

1) 文件默认权限

2) 文件的隐藏属性:

3) 文件特殊权限

5.6 命令和文件的查询

1) 脚本文件名的查询which

2) 文件名的查找

            find [PATH] [option] [action]
            find /etc -newer /etc/passwd
            find /home -user lvhongbin 把某用户的所有文件都找出来

六、 Linux磁盘与文件系统的管理

6.1 EXT2文件系统

1) 认识EXT2文件系统

2) EXT2文件系统

3) 注意:

6.2 相关命令

6.3 目录树与其他文件系统

1) 文件的读取流程:

            16777283 drwxr-xr-x. 2 lvhongbin lvhongbin 1024 Jan 1 17:42 text.text

2) 文件的写入流程:

3) 数据存放区域:inode table,data block;

4) 数据不一致的状态(Inconsistent)

5) 日志文件系统

6) Linux文件系统的操作

7) 挂载点(mount point)的意义与其他文件系统

            // 查看本linux系统支持的文件系统有哪些
            # ls -l /lib/modules/$(uname -r)/kernel/fs

            //查看加载到内存中的文件系统有哪些
            cat /proc/filesystems

8) Linux VFS

6.4 文件系统的简单操作

1) 列出文件系统的整体磁盘使用量:df [-ahikHTm] [目录或者文件名]

            // 1K-blocks下面数字的单位是1KB;
            // Mounted on表示磁盘挂载的目录所在(挂载点)df读取的是superblock里面的信息,所以显示结果的速度非常快速。
            [root@localhost /]# df -a
            Filesystem              1K-blocks    Used Available Use% Mounted on
            rootfs                          -       -         -    - /
            sysfs                           0       0         0    - /sys
            proc                            0       0         0    - /proc
            devtmpfs                  1916980       0   1916980   0% /dev

2) 评估文件系统的磁盘使用量:du [-ahskm] 文件或者目录名称

3) 连接文件ln

            Ln [-sf] 源文件 目标文件

6.5 磁盘的分区,格式化,检验和挂载

1) 新买的硬盘如何使用:

2) 磁盘分区

            [root@localhost Desktop]# fdisk -l

            Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectors
            Units = sectors of 1 * 512 = 512 bytes
            Sector size (logical/physical): 512 bytes / 512 bytes
            I/O size (minimum/optimal): 512 bytes / 512 bytes
            Disk label type: dos
            Disk identifier: 0x000cee2e

               Device Boot      Start         End      Blocks   Id  System
            /dev/sda1   *        2048     2099199     1048576   83  Linux
            /dev/sda2         2099200   167772159    82836480   8e  Linux LVM

            Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
            Units = sectors of 1 * 512 = 512 bytes
            Sector size (logical/physical): 512 bytes / 512 bytes
            I/O size (minimum/optimal): 512 bytes / 512 bytes


            Disk /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
            Units = sectors of 1 * 512 = 512 bytes
            Sector size (logical/physical): 512 bytes / 512 bytes
            I/O size (minimum/optimal): 512 bytes / 512 bytes


            Disk /dev/mapper/centos-home: 27.0 GB, 26969374720 bytes, 52674560 sectors
            Units = sectors of 1 * 512 = 512 bytes
            Sector size (logical/physical): 512 bytes / 512 bytes
            I/O size (minimum/optimal): 512 bytes / 512 bytes

3) 磁盘格式化mkfs(make file system)

            [root@localhost Desktop]# mkfs
            mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.fat     mkfs.minix   mkfs.msdos   mkfs.vfat    mkfs.xfs

4) 磁盘检验:fsck(file system check),badblocks(坏道检查)

5) 磁盘挂载与卸载

6) 内存交换空间swap的构建


七、 文件与文件系统的压缩与打包

7.1 常见的压缩命令

公共类是代码重用的一种形式,它将各个公用功能模块经常调用的方法提取到公用的Java类中,例如数据库的Dao类容纳了所有访问数据库的方法,并同时管理这数据库的连接和关闭,这样不但实现了代码的重用,还提高了程序的性能和代码的可读性。

1) compress

2) gzip

3) bzip2

4) tar

7.2 完整的备份工具dump和恢复工具restore

-能够备份实时的文件系统,设立9等级,0等级表示完整的实时备份,level 1表示实时文件系统与level 0 比较后差异部分的备份,level 2~9以此类推。 如果找不到dump命令,需要安装,命令为

            yum -y install dump
            Dump [-Suvj] [-level] [-f 备份文件] 待备份数据
  • -S:仅列出后面带备份数据需要多少磁盘空间才能够备份文件
  • -u;将此次dump的时间记录到/etc/dumpdates文件中
  • -v:将备份的过程显示出来
  • -j:加入bzip2的压缩程序支持

1) 当备份的是单一文件系统时;

2) 当备份的只是目录,而非单一文件系统时;


八、 vim程序编辑工具

8.1 vi与vim

1) vi的使用

2) 注意

            [lvhongbin@MiWiFi-R3G-srv test]$ alias
            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 perlll='eval `perl -Mlocal::lib`'
            alias vi='vim'
            alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

8.2 一些常用的命令

8.3 Vim的文件保存,恢复与打开时的警告信息

            E325: ATTENTION
            Found a swap file by the name "../tem/.test1.txt.swp"
                      owned by: lvhongbin   dated: Wed Jan  3 13:45:40 2018
                     file name: ~lvhongbin/Desktop/tem/test1.txt
                      modified: YES
                     user name: lvhongbin   host name: MiWiFi-R3G-srv
                    process ID: 76718
            While opening file "../tem/test1.txt"
                         dated: Wed Jan  3 11:54:59 2018

            (1) Another program may be editing the same file.  If this is the case,
                be careful not to end up with two different instances of the same
                file when making changes.  Quit, or continue with caution.
            (2) An edit session for this file crashed.
                If this is the case, use ":recover" or "vim -r ../tem/test1.txt"
                to recover the changes (see ":help recovery").
                If you did this already, delete the swap file "../tem/.test1.txt.swp"
                to avoid this message.

            Swap file "../tem/.test1.txt.swp" already exists!
            [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

8.4 其他操作与语系转换

1) 块选择(Visual Block)

2) 多文件操作

3) 多窗口功能

4) 语系转换


九、 bash

9.1 硬件,内核,shell和bash的关系

1) Shell的特点:

2) bash的特点:

3) Bash的内部命令:type

            // 查询命令是来自内部命令builtin还是alias抑或是外部命令file,类似于which的功能;
            Type [-tpa]> - name:

4) 如果一行太长写不完,可以用\[Enter]将[Enter]转义使之不具备执行命令的功能;

9.2 shell的变量功能

1) 变量的显示和设置:

2) 设置规则:

3) 返单引号(`)的作用

4) 环境变量的功能

            // export
            [root@MiWiFi-R3-srv software]# export
            declare -x COLORTERM="truecolor"
            declare -x DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-RaRlOvxfBB,guid=e24a18f0dc1699856cb3e2f45b08dc56"
            declare -x DESKTOP_SESSION="gnome-classic"
            declare -x DISPLAY=":0"
            declare -x GDMSESSION="gnome-classic"
            declare -x GDM_LANG="en_US.UTF-8"
            declare -x GNOME_DESKTOP_SESSION_ID="this-is-deprecated"

            // env
            [root@MiWiFi-R3-srv software]# env | sort
            COLORTERM=truecolor
            DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-RaRlOvxfBB,guid=e24a18f0dc1699856cb3e2f45b08dc56
            DESKTOP_SESSION=gnome-classic
            DISPLAY=:0
            GDM_LANG=en_US.UTF-8
            GDMSESSION=gnome-classic
            GNOME_DESKTOP_SESSION_ID=this-is-deprecated

5) $的功能

            [lvhongbin@MiWiFi-R3G-srv tem]$ $$
            bash: 25672: command not found...擦头

6) ?的功能

            // 返回0表示没有错误,其他错误码的含义有不同的distribution版本决定
            [root@MiWiFi-R3-srv software]# ?
            bash: ?: command not found...
            [root@MiWiFi-R3-srv software]# $?
            bash: 127: command not found...

            [root@MiWiFi-R3-srv software]# echo ${name}
            lvhongbin
            [root@MiWiFi-R3-srv software]# $?
            bash: 0: command not found...

7) OSTYPE,HOSTYPE,MACHTYPE

            [lvhongbin@MiWiFi-R3G-srv tem]$ echo $OSTYPE
            linux-gnu
            [lvhongbin@MiWiFi-R3G-srv tem]$ echo $HOSTTYPE
            x86_64
            [lvhongbin@MiWiFi-R3G-srv tem]$ echo $MACHTYPE
            x86_64-redhat-linux-gnu

8) 变量键盘的读取,数组和声明

            [root@MiWiFi-R3-srv software]# read -p "please input your name: " -t 30 name
            please input your name: lvhongbin
            [root@MiWiFi-R3-srv software]# echo ${name}
            lvhongbin

9) declare/typeset

            [root@MiWiFi-R3-srv software]# sum=10+20+30
            [root@MiWiFi-R3-srv software]# echo ${sum}
            10+20+30
            [root@MiWiFi-R3-srv software]# declare -i sum=10+20+30
            [root@MiWiFi-R3-srv software]# echo ${sum}
            60

            [root@MiWiFi-R3-srv software]# export | grep sum
            declare -ix sum="60"

            // 数组
            [root@MiWiFi-R3-srv software]# value[0]="h"
            [root@MiWiFi-R3-srv software]# value[1]="i"
            [root@MiWiFi-R3-srv software]# echo ${value}
            h
            [root@MiWiFi-R3-srv software]# echo ${value[0]}
            h
            [root@MiWiFi-R3-srv software]# echo ${value[1]}
            i

10) 与文件系统的及程序的限制关系:ulimit;

11) 变量内容的删除

            [root@MiWiFi-R3-srv software]# id=116020910160
            [root@MiWiFi-R3-srv software]# echo ${id#1*6}
            020910160
            [root@MiWiFi-R3-srv software]# echo ${id}
            116020910160
            [root@MiWiFi-R3-srv software]# echo ${id##1*6}
            0
            [root@MiWiFi-R3-srv software]# echo ${id}
            116020910160
            [root@MiWiFi-R3-srv software]# echo ${id$0*6}
            bash: ${id$0*6}: bad substitution

12) 变量内容的替换

13) 变量内容的存在性检测

14) 命名别名和去除别名

15) 历史命令:history

9.3 Bash shell的操作环境

1) 命令运行的顺序:

2) bash的登陆和欢迎信息

9.4 Bash shell的环境配置文件(太复杂了,不看)

1)logic shell VS non-logic shell

9.5 数据的重定向

1) 输出>和>>

2) 输入<和<<

            [lvhongbin@MiWiFi-R3G-srv Desktop]$ cat > test2.txt
            Hello   
            I'm writing!
            [Ctrl]+d 表示结束输入
            [lvhongbin@MiWiFi-R3G-srv Desktop]$ cat > test2.txt << "eof"
            > Input
            > success!
            > eof

3) 什么场合会用到数据的重定向

4) >/dev/null 2>&1 详解一串脚印的博客

5)> /dev/null 详解 一串脚印的博客

6)> command > file 2>file 与command > file 2>&1的区别 一串脚印的博客

9.6 命令与管道命令

1) 命令的合并

            ls -l 文件名 || touch 文件名
  • &&命令会传递前一个命令的$?值,如果$?\<>0,则执行第二个命令,若$?==0则跳过第二命令,并把$?==0传递到第三个命令
  • 管道命令pipe cmd1 | cmd2
  • 管道命令仅会处理standard output,对于standard error output会予以忽略;
  • 管道命令必须能接收第一个命令的数据成为standard input继续处理才行;
  • 常用的管道命令如less(将大量的输出做成可翻页的形式),more,head,tail

2) 选取命令:cut, grep

            [lvhongbin@MiWiFi-R3G-srv Desktop]$ ls -al .. | cut -c 16- | cut -c -9
            [lvhongbin@MiWiFi-R3G-srv Desktop]$ ls -al .. | cut -c 16- | cut -c -9 |grep --color=auto "lvhongbin"

            统计当前目录下文件的个数(不包括目录)
            $ ls -l | grep "^-" | wc -l
            1
            统计当前目录下文件的个数(包括子目录)
            $ ls -lR| grep "^-" | wc -l
            1
            查看某目录下文件夹(目录)的个数(包括子目录)
            $ ls -lR | grep "^d" | wc -l

3) 排序命令:sort,wc, uniq

            -t和-k一般一起使用:
            [lvhongbin@MiWiFi-R3G-srv Desktop]$ ls -al .. | sort -t ' ' -k 2
            [lvhongbin@MiWiFi-R3G-srv Desktop]$ last  
            lvhongbi pts/0        :0               Wed Jan  3 03:01 - 03:02  (00:00)    
            lvhongbi :0           :0               Wed Jan  3 03:00 - 03:11  (00:10)    
            reboot   system boot  3.10.0-693.el7.x Wed Jan  3 02:58 - 20:01  (-6:-56)

            wtmp begins Wed Jan  3 02:58:11 2018
            last \| grep [a-zA-Z] \| grep -r “wtmp” \| wc -l

4) 双向重定向:tee

5) 字符转换命令:tr,col,join,paste,expand

            如tr ‘[a-z]’ ‘[A-z]’

6) 切割命令:split

            [lvhongbin@MiWiFi-R3G-srv Desktop]$ split -b 1k 要分割的文件 前导文件名

7) 关于减号:-

            tar -cvf - /home \| tar -xvf –

十、 正则表达式

10.1 基础正则表达式

1) Grep的高级用法

            Grep [-A] [-B]

2) 基础正则表达式字符,用在‘’内部

10.2 拓展正则表达式字符

1) 拓展正则表达式字符,用在‘’内部

10.3 sed工具

            sed [-nefr] ‘动作’

10.4 格式化打印:printf

            ‘打印格式’ 实际内容
            printf  '%15s\t %5.2f\t %5.2f\t %5.2f\t %5.2f\t \n' $(cat text1.txt)
                  lvhongbin  123.00  44.10   22.00    2.00   
                 lvhongchao   3.40    2.33   31.11    3.20

10.5 awk:好用的数据处理工具

1) 介绍

2) 整个awk的处理流程:

            文件stdin | awk ‘条件{printf “正则表达式”, $1, $2,```$n, “自己的内容”}’
            cat text1.txt | awk 'NR<3{printf "%10s %5.2f  %5.2f  %5.2f  %5.2f %10s %10s\n",$1, $2, $3, $4, $5, " total:" NF, " line:" NR}'

10.6 文件比较工具


十一、 Shell Script

11.1 基础知识

1) 简单的shell script练习

        // sh01.sh
        #!/bin/bash
        # Program:
        #   User input his/her first name and last name. Then print the full name
        # History:
        # 2018-05-27 Lvhongbin      First Relsase

        read -p "Plasea input you first name: " firstName
        read -p "Plasea input you last  name: " lastName

        # echo -e 意思是允许后面的内容进行反斜杠转义
        echo -e "\nYour full name is: ${firstName} ${lastName}"

        // 运行结果:直接运行
        [root@MiWiFi-R3-srv Desktop]# chmod 4777 sh01.sh
        // 此处必须要./
        [root@MiWiFi-R3-srv Desktop]# ./sh01.sh
        Plasea input you first name: lv
        Plasea input you last  name: hongbin

        Your full name is: lv hongbin 
        //在shell script的父进程无法得到子进程的变量
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${firstName}
        //在shell script的父进程无法得到子进程的变量
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${lastName}

        // 运行结果:使用sh命令
        [lvhongbin@MiWiFi-R3-srv Desktop]$ sh sh01.sh
        Plasea input you first name: lv
        Plasea input you last  name: hongbin

        Your full name is: lv hongbin
        //在shell script的父进程无法得到子进程的变量
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${firstName}
        //在shell script的父进程无法得到子进程的变量
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${lastName}

2) 执行方式的区别

        [lvhongbin@MiWiFi-R3-srv Desktop]$ source sh01.sh
        Plasea input you first name: lv       
        Plasea input you last  name: hongbin

        Your full name is: lv hongbin
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${firstName}
        lv
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${lastName}
        hongbin

3) 善用判别式

        [lvhongbin@MiWiFi-R3-srv Desktop]$ test -e sh01.sh && echo "exist" || echo "not exist"
        exist

        # 如果没有文件夹,则创建
        if [ ! -d $result_name ];then
              mkdir -p $result_name
        fi
        [lvhongbin@MiWiFi-R3-srv Desktop]$ test 1 -ge 2 && echo "1>=2" || echo "1<2"
        1<2
        [lvhongbin@MiWiFi-R3-srv Desktop]$ test -r sh01.sh && echo "readable" || echo "unreadable"
        readable
        [lvhongbin@MiWiFi-R3-srv Desktop]$ [ ${lastName} == "hongbin" ] && echo "equal" || echo "unequal"
        equal
        [lvhongbin@MiWiFi-R3-srv Desktop]$ [ ${lastName} == "lv" ] && echo "equal" || echo "unequal"
        unequal

        // sh02.sh
        #!/bin/bash
        # Program:
        #   This proggress shows the user's choise
        # History:
        # 2018-05-27 Lvhongbin      First Relsase

        read -p "Please choose your choise (Y/N): " yn
        [ ${yn} == "Y" -o  ${yn} == "y" ] && echo "OK, continue" && exit 0
        [ ${yn} == "N" -o  ${yn} == "n" ] && echo "Oh, interrupt!" && exit 0
            echo "I don't know what your chiose is" && exit 0

        [lvhongbin@MiWiFi-R3-srv Desktop]$ sh sh02.sh
        Please choose your choise (Y/N): Y
        OK, continue
        [lvhongbin@MiWiFi-R3-srv Desktop]$ sh sh02.sh
        Please choose your choise (Y/N): n
        Oh, interrupt!
        [lvhongbin@MiWiFi-R3-srv Desktop]$ sh sh02.sh
        Please choose your choise (Y/N): q
        I don't know what your chiose is
        [lvhongbin@MiWiFi-R3-srv Desktop]$

4) 默认变量

        # sh03.sh
        #!/bin/bash
        # Program:
        #   This proggress shows default parameters
        # History:
        # 2018-05-27 Lvhongbin      First Relsase

        echo "The script's name is ==> $0"
        echo "The argument[0] is ==> $1"
        echo "The argument[1] is ==> $2"
        # 这里需要用引号吧$@括起来,其实括不括起来都无所谓
        echo "The arguments is ==> '$@'"
        echo "The arguments.length is ==> '$#'"
        shift && echo -e "shift \n" 
        echo "The script's name is ==> $0"
        echo "The argument[0] is ==> $1"
        echo "The argument[1] is ==> $2"
        # 这里需要用引号吧$@括起来,其实括不括起来都无所谓
        echo "The arguments is ==> '$@'"
        echo "The arguments.length is ==> '$#'"
        shift 2 && echo -e "shift 2 \n"
        echo "The script's name is ==> $0"
        echo "The argument[0] is ==> $1"
        echo "The argument[1] is ==> $2"
        # 这里需要用引号吧$@括起来,其实括不括起来都无所谓
        echo "The arguments is ==> '$@'"
        echo "The arguments.length is ==> '$#'"

        //结果
        [lvhongbin@MiWiFi-R3-srv Desktop]$ sh sh03.sh one two three four five six
        The script's name is ==> sh03.sh
        The argument[0] is ==> one
        The argument[1] is ==> two
        The arguments is ==> 'one two three four five six'
        The arguments.length is ==> '6'
        shift

        The script's name is ==> sh03.sh
        The argument[0] is ==> two
        The argument[1] is ==> three
        The arguments is ==> 'two three four five six'
        The arguments.length is ==> '5'
        shift 2

        The script's name is ==> sh03.sh
        The argument[0] is ==> four
        The argument[1] is ==> five
        The arguments is ==> 'four five six'
        The arguments.length is ==> '3'

5) 获取命令返回值

        testing=$(netstat -tuln | grep ":80") #检测80端口,并赋给testing变量

        [lvhongbin@MiWiFi-R3-srv Desktop]$ testing=$(netstat -tuln | grep ":22")
        [lvhongbin@MiWiFi-R3-srv Desktop]$ echo ${testing}
        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN

11.2 条件判断式

1) if.. then..

        if [ condition ] ; then 
            # do something
        fi
        [ condition1 ] || [ condition2 ]
        [ condition1 ] && [ condition2 ]

2) 多重复杂判断式

        if [ condition ] ; then 
            # do something
        elif [ condition ] ; then
            # do something
        else
            # do something
        fi

3) 利用case..esac

        case $1 in 
            "内容1")
                # do something
            ;;
            "内容2")
                # do something
            ;;
            *)
                # do something
            ;;
        esac

11.3 循环

1) while do done

        while [ condition ]
        do
            #something
        done

2) until do done

        until [ condition ]
        do
            # do something
        done

3) for do done

        for var in con1 con2 con3...
        do
            # do something
        done


        # pingip.sh
        #!/bin/bash
        # Program
        #       Use ping command to check the network's PC state.
        # History
        # 2015/07/17    VBird   first release
        PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
        export PATH
        network="192.168.1"              # 先定義一個網域的前面部分!
        for sitenu in $(seq 1 100)       # seq 為 sequence(連續) 的縮寫之意
        do
            # 底下的程式在取得 ping 的回傳值是正確的還是失敗的!然后把取得的信息扔在/dev/null中不显示在屏幕
                ping -c 1 -w 1 ${network}.${sitenu} &> /dev/null && result=0 || result=1
            # 開始顯示結果是正確的啟動 (UP) 還是錯誤的沒有連通 (DOWN)
                if [ "${result}" == 0 ]; then
                        echo "Server ${network}.${sitenu} is UP."
                else
                        echo "Server ${network}.${sitenu} is DOWN."
                fi
        done
        for((i=0, i<10, i++)) 
        do
            s=$( ($s+$i) )
        done

11.4 函数function

1) 范式

        # batchChangeFileName.sh
        #!/bin/bash
        # Program
        #       Create a dir where store files and change files name with parallel batch.
        # History
        # 2018/05/27    Lvhongbin   first release

        read -p "Please input your dir: " dir
        read -p "Please input your file name: " file
        while [ "$dir" == "" ]
        do
            read -p "Please input your dir: " dir
        done

        function creatFiles() {
        if [ ! -d "$1" ] ; then
            mkdir $1
        fi

        if [ -z "$2" ] ; then
            fileName="fileName"
        else
            fileName=$2
        fi

        for((i=1;i<=10;i++))
        do
            test -e $1/$2${i} && echo "$2${i} has existed" || touch $1/$2${i}
        done
        }

        creatFiles ${dir} ${file}

        tar -c ${dir} -f ${dir}.tar

        function changeFileName() {

            # ls -l 不能省略成ll
            echo "The number of file is $(ls -l ${dir} | grep "^-" | wc -l)"
            for name in $(ls ${dir}) 
            do 
                # 把在屏幕中显示的信息扔在/dev/null中不显示
                echo ${name} | grep "${file}[0-9]$" &> /dev/null  && mv ${dir}/${name} ${dir}/${name/${file}/${file}0} 
            done
        }

        changeFileName

11.5 调试

1) bash

            bash -n batchChangeFileName.sh

十二、 软件安装

12.1 make和configure

1) make和configure的关系

2) Tarball

3) makefile

        目标(target): 目标文件1 目标文件2
        <tab>   gcc -o 新欲建的可执行文件 目标文件1 目标文件2
        # Filename: Makefile

        # Description: Makefile findGF.o fight.o

        # Version: 1.0

        # Created: 2018/05/28

        # Revision: none

        # Compiler: make

        # Author: Lv Hongbin

        # Company: Shanghai JiaoTong Univerity

        # **************************************************************/

        # 变量内容等号两边允许有空格
        OBJS=findGF.o fight.o

        # $@=main

        main: ${OBJS}
            gcc -o $@ ${OBJS}
        clean:
            rm -f main ${OBJS}
        /* ***************************************************************
         *
         * * Filename: FindGF.c
         *
         * * Description:linking and compiling test
         *
         * * Version: 1.0
         *
         * * Created: 2018/05/28
         *
         * * Revision: none
         *
         * * Compiler: gcc
         *
         * * Author: Lv Hongbin
         *
         * * Company: Shanghai JiaoTong Univerity
         *
         * * **************************************************************/

        #include<stdio.h>
        int main(void) {
            printf("Let's look for a girl\n");
            fight();
        }
        /* ***************************************************************
         *
         * * Filename: Fight.c
         *
         * * Description:linking and compiling test
         *
         * * Version: 1.0
         *
         * * Created: 2018/05/28
         *
         * * Revision: none
         *
         * * Compiler: gcc
         *
         * * Author: Lv Hongbin
         *
         * * Company: Shanghai JiaoTong Univerity
         *
         * * **************************************************************/

        #include<stdio.h>
        void fight(void) {
            printf("I'm learning C programming language! \n");
            printf("I'm earning money! \n");
            printf("I'm keeping fit! \n");
        }

4) 执行步骤

12.2 软件管理器RPM、RPMS和YUM

1) RPM

        rpm -ivh package_name

2) RPMS

3) YUM


十三、 进程与程序管理

13.1 进程与程序

1) 定义

2) 父进程与子进程

13.2 工作管理

1) 定义

2) job control管理

            [lvhongbin@MiWiFi-R3-srv Desktop]$ touch log.txt
            [lvhongbin@MiWiFi-R3-srv Desktop]$ tar -jcv ./practise -f ./practise.tar.bz2 > log.txt 2>&1 &
            [1] 74069

            [lvhongbin@MiWiFi-R3-srv Desktop]$ cat log.txt
            ./practise/
            ./practise/batchChangeFileName.sh
            ./practise/hello/
            ./practise/hello/src/
            ./practise/hello/build/
            ./practise/hello/build/config.gypi
            ./practise/hello/build/Makefile
            ./practise/hello/build/hello.target.mk
            ./practise/hello/build/binding.Makefile
            ./practise/hello/build/Release/
            ./practise/hello/build/Release/obj.target/
            ./practise/hello/build/Release/obj.target/hello/
            ./practise/hello/build/Release/obj.target/hello/src/
            ./practise/hello/build/Release/.deps/
            ./practise/hello/build/Release/.deps/Release/
            ./practise/hello/build/Release/.deps/Release/obj.target/
            ./practise/hello/build/Release/.deps/Release/obj.target/hello/
            ./practise/hello/build/Release/.deps/Release/obj.target/hello/src/
            ./practise/hello_world/build/Release/.deps/Release/hello.node.d
            ./practise/hello_world/build/Release/hello.node
            ./practise/hello_world/hello.js
            ./practise/hello_world/hi.js
            ./practise/hello_world/test.js
            ./practise/pingip.sh
            ./practise/sh01.sh
            ./practise/sh02.sh
            ./practise/sh03.sh
            ./practise/text.txt
            ./practise/findGF/
            ./practise/findGF/fight.c
            ./practise/findGF/findGF.c
            ./practise/findGF/Makefile
            ./practise/findGF/findGF.o
            ./practise/findGF/fight.o
            ./practise/findGF/main
            ./practise/findGF.tar.bz2
            [1]+  Done                    tar -jcv ./practise -f ./practise.tar.bz2 > log.txt 2>&1
            [lvhongbin@MiWiFi-R3-srv Desktop]$ vim log.txt

            [1]+  Stopped                 vim log.txt
            [lvhongbin@MiWiFi-R3-srv Desktop]$ jobs -l
            [1]+ 74296 Stopped                 vim log.txt
            [lvhongbin@MiWiFi-R3-srv Desktop]$ vim ./practise/test.txt

            [2]+  Stopped                 vim ./practise/test.txt
            [lvhongbin@MiWiFi-R3-srv Desktop]$ fg %1
            vim log.txt

            [lvhongbin@MiWiFi-R3-srv Desktop]$ kill -l
             1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
             6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
            11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
            16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
            21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
            26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
            31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
            38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
            43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
            48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
            53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
            58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
            63) SIGRTMAX-1  64) SIGRTMAX

3) 进程的查看

            lvhongbin@MiWiFi-R3-srv Desktop]$ ps aux
            USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
            root          1  0.0  0.1  46164  6520 ?        Ss   May26   1:07 /usr/lib/systemd/systemd --system --deserialize 15
            root          2  0.0  0.0      0     0 ?        S    May26   0:00 [kthreadd]
            root          3  0.0  0.0      0     0 ?        S    May26   0:02 [ksoftirqd/0]
            root          5  0.0  0.0      0     0 ?        S<   May26   0:00 [kworker/0:0H]
            root          7  0.0  0.0      0     0 ?        S    May26   0:01 [migration/0]
            root          8  0.0  0.0      0     0 ?        S    May26   0:00 [rcu_bh]

            [lvhongbin@MiWiFi-R3-srv Desktop]$ ps -l
            F S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
            0 S  1000  67929  67919  0  80   0 - 29152 do_wai pts/0    00:00:00 bash
            4 S  1000  73055  73054  0  80   0 - 29153 do_wai pts/0    00:00:00 bash
            0 R  1000  74688  73055  0  80   0 - 37245 -      pts/0    00:00:00 ps
            [lvhongbin@MiWiFi-R3-srv Desktop]$ top -d 5

            top - 17:12:23 up 2 days,  5:11,  2 users,  load average: 0.15, 0.13, 0.10
            Tasks: 202 total,   3 running, 199 sleeping,   0 stopped,   0 zombie
            %Cpu(s):  8.9 us,  2.9 sy,  0.0 ni, 88.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
            KiB Mem :  3865308 total,   152436 free,  1484608 used,  2228264 buff/cache
            KiB Swap:  2097148 total,  2095156 free,     1992 used.  1895640 avail Mem

               PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                       
             12792 lvhongb+  20   0 2414388 338476  50036 S  19.7  8.8  55:09.93 gnome-shell                                                                                                                                   
              2776 root      20   0  400548 116436  32948 S   3.6  3.0  16:10.81 X                                                                                                                                             
             14443 lvhongb+  20   0 2140496 378416 157404 S   1.4  9.8 329:12.89 Web Content                                                                                                                                   
             67919 lvhongb+  20   0  729856  23584  14676 S   0.8  0.6   0:08.63 gnome-terminal-                                                                                                                               
             13019 lvhongb+  20   0  386616  20492  15044 R   0.4  0.5   3:02.13 vmtoolsd                                                                                                                                      
             14385 lvhongb+  20   0 2619264 305316 118500 S   0.4  7.9  66:06.39 firefox                                                                                                                                       
                 9 root      20   0       0      0      0 R   0.2  0.0   0:41.44 rcu_sched                                                                                                                                     
               410 root      20   0       0      0      0 S   0.2  0.0   0:35.63 xfsaild/dm-0                                                                                                                                  
             12819 lvhongb+  20   0  451664   6796   3284 S   0.2  0.2   0:56.11 ibus-daemon                                                                                                                                   
             13005 lvhongb+  20   0  529540  15724  10304 S   0.2  0.4   0:00.49 abrt-applet                                                                                                                                   
             74676 root      20   0       0      0      0 S   0.2  0.0   0:00.32 kworker/1:0                                                                                                                                   
             74790 lvhongb+  20   0  157784   2368   1580 R   0.2  0.1   0:00.65 top
            [lvhongbin@MiWiFi-R3-srv Desktop]$ pstree
            systemd─┬─ModemManager───2*[{ModemManager}]
                    ├─NetworkManager─┬─dhclient
                    │                └─2*[{NetworkManager}]
                    ├─VGAuthService
                    ├─2*[abrt-watch-log]
                    ├─abrtd
                    ├─accounts-daemon───2*[{accounts-daemon}]
                    ├─agetty
                    ├─alsactl
                    ├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}
                    │                 └─3*[{at-spi-bus-laun}]
                    ├─at-spi2-registr───2*[{at-spi2-registr}]
                    ├─atd
                    ├─auditd─┬─audispd─┬─sedispatch
                    │        │         └─{audispd}
                    │        └─{auditd}
                    ├─avahi-daemon───avahi-daemon
                    ├─bluetoothd
                    ├─chronyd
                    ├─colord───2*[{colord}]
                    ├─crond
                    ├─cupsd
                    ├─2*[dbus-daemon───{dbus-daemon}]
                    ├─dbus-launch
                    ├─dconf-service───2*[{dconf-service}]
                    ├─dnsmasq───dnsmasq
                    ├─evolution-addre─┬─evolution-addre───5*[{evolution-addre}]
                    │                 └─5*[{evolution-addre}]
                    ├─evolution-calen─┬─evolution-calen───7*[{evolution-calen}]
                    │                 ├─evolution-calen───5*[{evolution-calen}]
                    │                 └─5*[{evolution-calen}]
                    ├─evolution-sourc───4*[{evolution-sourc}]
                    ├─firefox─┬─Web Content───22*[{Web Content}]
                    │         └─45*[{firefox}]
                    ├─firewalld───{firewalld}
                    ├─gconfd-2
                    ├─gdm─┬─X───3*[{X}]
                    │     ├─gdm-session-wor─┬─gnome-session-b─┬─abrt-applet───2*[{abrt-applet}]
                    │     │                 │                 ├─gnome-settings-───4*[{gnome-settings-}]
                    │     │                 │                 ├─gnome-shell─┬─ibus-daemon─┬─ibus-dconf───3*[{ibus-dconf}]
                    │     │                 │                 │             │             ├─ibus-engine-lib───2*[{ibus-engine-lib}]
                    │     │                 │                 │             │             ├─ibus-engine-sim───2*[{ibus-engine-sim}]
                    │     │                 │                 │             │             └─2*[{ibus-daemon}]
                    │     │                 │                 │             └─10*[{gnome-shell}]
                    │     │                 │                 ├─gnome-software───3*[{gnome-software}]
                    │     │                 │                 ├─nautilus-deskto───3*[{nautilus-deskto}]
                    │     │                 │                 ├─seapplet
                    │     │                 │                 ├─ssh-agent
                    │     │                 │                 ├─tracker-extract───14*[{tracker-extract}]
                    │     │                 │                 ├─tracker-miner-a───3*[{tracker-miner-a}]
                    │     │                 │                 ├─tracker-miner-f───3*[{tracker-miner-f}]
                    │     │                 │                 ├─tracker-miner-u───3*[{tracker-miner-u}]
                    │     │                 │                 └─3*[{gnome-session-b}]
                    │     │                 └─2*[{gdm-session-wor}]
                    │     └─3*[{gdm}]
                    ├─glib-pacrunner───2*[{glib-pacrunner}]
                    ├─gnome-keyring-d───3*[{gnome-keyring-d}]
                    ├─gnome-shell-cal───6*[{gnome-shell-cal}]
                    ├─gnome-terminal-─┬─bash───su───bash───su───bash───pstree
                    │                 ├─gnome-pty-helpe
                    │                 └─3*[{gnome-terminal-}]
                    ├─goa-daemon───4*[{goa-daemon}]
                    ├─goa-identity-se───3*[{goa-identity-se}]
                    ├─gsd-printer───2*[{gsd-printer}]
                    ├─gssproxy───5*[{gssproxy}]
                    ├─gvfs-afc-volume───3*[{gvfs-afc-volume}]
                    ├─gvfs-goa-volume───2*[{gvfs-goa-volume}]
                    ├─gvfs-gphoto2-vo───2*[{gvfs-gphoto2-vo}]
                    ├─gvfs-mtp-volume───2*[{gvfs-mtp-volume}]
                    ├─gvfs-udisks2-vo───2*[{gvfs-udisks2-vo}]
                    ├─gvfsd───2*[{gvfsd}]
                    ├─gvfsd-dnssd───2*[{gvfsd-dnssd}]
                    ├─gvfsd-fuse───5*[{gvfsd-fuse}]
                    ├─gvfsd-metadata───2*[{gvfsd-metadata}]
                    ├─gvfsd-network───3*[{gvfsd-network}]
                    ├─gvfsd-recent───2*[{gvfsd-recent}]
                    ├─gvfsd-trash───2*[{gvfsd-trash}]
                    ├─ibus-daemon─┬─ibus-dconf───3*[{ibus-dconf}]
                    │             └─2*[{ibus-daemon}]
                    ├─2*[ibus-x11───2*[{ibus-x11}]]
                    ├─irqbalance
                    ├─ksmtuned───sleep
                    ├─libvirtd───15*[{libvirtd}]
                    ├─lsmd
                    ├─lvmetad
                    ├─master─┬─pickup
                    │        └─qmgr
                    ├─mission-control───3*[{mission-control}]
                    ├─nautilus───3*[{nautilus}]
                    ├─packagekitd───2*[{packagekitd}]
                    ├─polkitd───5*[{polkitd}]
                    ├─pulseaudio───2*[{pulseaudio}]
                    ├─rngd
                    ├─rsyslogd───2*[{rsyslogd}]
                    ├─rtkit-daemon───2*[{rtkit-daemon}]
                    ├─smartd
                    ├─sshd
                    ├─systemd-journal
                    ├─systemd-logind
                    ├─systemd-udevd
                    ├─tracker-store───7*[{tracker-store}]
                    ├─tuned───4*[{tuned}]
                    ├─udisksd───4*[{udisksd}]
                    ├─upowerd───2*[{upowerd}]
                    ├─vmtoolsd───{vmtoolsd}
                    ├─vmtoolsd
                    ├─wpa_supplicant
                    └─xdg-permission-───2*[{xdg-permission-}]

4) 进程的优先级

            [lvhongbin@MiWiFi-R3-srv Desktop]$ ps -l
            F S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
            0 S  1000  67929  67919  0  80   0 - 29152 do_wai pts/0    00:00:00 bash
            4 S  1000  73055  73054  0  80   0 - 29153 do_wai pts/0    00:00:00 bash
            0 R  1000  75105  73055  0  80   0 - 37245 -      pts/0    00:00:00 ps
            [lvhongbin@MiWiFi-R3-srv Desktop]$ renice 10 67929
            67929 (process ID) old priority 0, new priority 10
            [lvhongbin@MiWiFi-R3-srv Desktop]$ ps -l
            F S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
            0 S  1000  67929  67919  0  90  10 - 29152 do_wai pts/0    00:00:00 bash
            4 S  1000  73055  73054  0  80   0 - 29153 do_wai pts/0    00:00:00 bash
            0 R  1000  75119  73055  0  80   0 - 37245 -      pts/0    00:00:00 ps

13.3 系统资源的查看

1) 相关命令

            [lvhongbin@MiWiFi-R3-srv Desktop]$ free
                          total        used        free      shared  buff/cache   available
            Mem:        3865308     1439404      192716      131888     2233188     1938440
            Swap:       2097148        1980     2095168
            [lvhongbin@MiWiFi-R3-srv Desktop]$ uname
            Linux
            [lvhongbin@MiWiFi-R3-srv Desktop]$ uname -a
            Linux MiWiFi-R3-srv 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

十四、 Linux中常见的网络命令

14.1 设置网络参数的命令

1) ifconfig,ifup,ifdown

            ifconfig {interface} {up/down} <==查看与启动接口