程序员书籍笔记 程序员书籍笔记
  • JavaScript
  • HTML/CSS
  • PHP
  • Python
  • Go
  • 数据库
  • 容器
  • 微服务
  • 消息队列
  • 搜索引擎
  • 大数据
  • 鸟哥Linux私房菜
其他
  • 大数据
  • 深度学习
APP下载 (opens new window)
GitHub (opens new window)
  • JavaScript
  • HTML/CSS
  • PHP
  • Python
  • Go
  • 数据库
  • 容器
  • 微服务
  • 消息队列
  • 搜索引擎
  • 大数据
  • 鸟哥Linux私房菜
其他
  • 大数据
  • 深度学习
APP下载 (opens new window)
GitHub (opens new window)
  • 鸟哥Linux私房菜

    • 基本概念
      • Linux与硬件搭配
      • 磁盘分区
        • 系统开机流程
        • BIOS和UEFI的区别
      • Linux安装
      • 首次登录与在线求助
        • 文本模式指令下达
        • Linux系统的在线求助
        • 简单文本编辑器 nano
        • 正确关机的方法
    • 文件权限与目录配置
    • 文件与目录管理
  • 系统
  • 鸟哥Linux私房菜
小游
2021-05-07

基本概念

# Linux与硬件搭配

各硬件装置在Linux中的文件名

image-20210513204719143

image-20210513204730121

# 磁盘分区

image-20210513205236230

# 系统开机流程

1.BIOS:开机主动执行的韧体,会认识第一个可开机的装置 2.MBR:第一个可开机装置的第一个扇区内的主要启动记录区块,内含开机管理程序 3.开机管理程序( boot loader):一支可读取核心文件来执行的软件 4.核心文件:开始操作系统的功能

# BIOS和UEFI的区别

image-20210513210253828

Linux是目录树结构,所有的文件都会在根目录下,那么我们如何把目录树与磁盘分区结合呢?答案是使用挂载

所谓的『挂载」就是利用一个目录当成进入点,将磁盘分区槽的数据放置在该目录下;也就是说进入该目录就可以读取该分区槽的意思。这个动作我们称为『挂载』,那个进入点的目录我们称为『挂载点』。由于整个 Linux系统最重要的是根目录,因此根目录一定需要挂载到某个分区槽的。至于其他的目录则可依用户自己的需求来给予挂载到不同的分区槽。

# Linux安装

初次接触 Linux:只要分区「/』及『swap」即可(这个月可以避免分区错误造成无法安装)

不知道你有没有发现,怎么我想要下载的档名会是 Centos-7-x8664 Everything-1503-01iso这样的格式?那个1503是啥东西啊?其实从 CentOS7之后,版本命名的依据就跟发表的日期有关了!那个 Centos-7讲的是7x版本,x8664指的是64位操作系统, Everything指的是包山包海的版本,1503指的是2015年的3月发表的版本,01.iso则得要与 Centos7搭配,所以是 Cento7.1版的意思!

后面就是安装虚拟机的过程了。这里我就不多解释了,这个不是重点。。

# 首次登录与在线求助

注销Linux直接使用 exit 命令(这个只是离开不是关机)

# 文本模式指令下达

一般来说,Linux系统命令格式如下

image-20210514165041965

image-20210514165105628

# 查看系统支持的语言

locale
1

image-20210514165244332

修改系统语言为英文

[root@localhost ~]# date
2021年 05月 14日 星期五 17:07:16 CST
[root@localhost ~]# LANG=en_US.utf8
[root@localhost ~]# export LC_ALL=en_US.utf8
#LANG只与输出讯息有关,若需要更改其他不同的信息,要同步更新 LC ALL才行
[root@localhost ~]# date
Fri May 14 17:08:38 CST 2021
1
2
3
4
5
6
7

# 基础指令操作

  • 显示日期与时间的指令:date
  • 显示日历的指令:cal
  • 简单好用的计算器:bc

时间格式化输出

[root@localhost ~]# date +%Y/%m/%d
2021/05/14
[root@localhost ~]# date +%H:%M
17:12
1
2
3
4

日历命令

如果我们想查看某年的日历,可以直接这样:

[root@localhost ~]# cal 2021
                               2021                               

       January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                1  2       1  2  3  4  5  6       1  2  3  4  5  6
 3  4  5  6  7  8  9    7  8  9 10 11 12 13    7  8  9 10 11 12 13
10 11 12 13 14 15 16   14 15 16 17 18 19 20   14 15 16 17 18 19 20
17 18 19 20 21 22 23   21 22 23 24 25 26 27   21 22 23 24 25 26 27
24 25 26 27 28 29 30   28                     28 29 30 31
31
        April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
             1  2  3                      1          1  2  3  4  5
 4  5  6  7  8  9 10    2  3  4  5  6  7  8    6  7  8  9 10 11 12
11 12 13 14 15 16 17    9 10 11 12 13 14 15   13 14 15 16 17 18 19
18 19 20 21 22 23 24   16 17 18 19 20 21 22   20 21 22 23 24 25 26
25 26 27 28 29 30      23 24 25 26 27 28 29   27 28 29 30
                       30 31
        July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
             1  2  3    1  2  3  4  5  6  7             1  2  3  4
 4  5  6  7  8  9 10    8  9 10 11 12 13 14    5  6  7  8  9 10 11
11 12 13 14 15 16 17   15 16 17 18 19 20 21   12 13 14 15 16 17 18
18 19 20 21 22 23 24   22 23 24 25 26 27 28   19 20 21 22 23 24 25
25 26 27 28 29 30 31   29 30 31               26 27 28 29 30

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

也可以精确到月

[root@localhost ~]# cal 5 2021
      May 2021      
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
1
2
3
4
5
6
7
8
9

bc计算器

这个计算器支持下面这几种操作

+加法 减法 ·*乘法 除法 ∧指数 %余数

[root@localhost ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
10*20
200
1
2
3
4
5
6
7

如果想退出,可以输入 quit,或者直接 ctrl+c

# 几个重要的热键 Tab ,ctrl-C, ctrl-d

TAB 可以用于命令的补全

ctrl+C 用于停止当前程序

ctrl+D 表示键盘输入结束,如果想退出shell窗口,可以直接按这个快捷键退出

shift+{ PageUP| Page down}按键

如果你在纯文本的画面中执行某些指令,这个指令的输出讯息相当长啊!所以导致前面的部份已经不在目前的屏幕画面中,所以你想要回头去瞧一瞧输出的讯息,那怎办?其实,你可以使用 [Shift]+ Page Up] 来往前翻页,也能够使用[ Shift]-+[ Page Down]来往后翻页!这两个组合键也是可以稍微记忆一下,在你要稍微往前翻画面时,相当有帮助

# Linux系统的在线求助

# 指令 --help 求助说明

下面简单介绍一下date的帮助文档,因为太长了,所以只截取部分

[root@localhost ~]# date --help
用法:date [选项]... [+格式]
 或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.

Mandatory arguments to long options are mandatory for short options too.
  -d, --date=STRING         display time described by STRING, not 'now'
  -f, --file=DATEFILE       like --date once for each line of DATEFILE
  -I[TIMESPEC], --iso-8601[=TIMESPEC]  output date/time in ISO 8601 format.
                            TIMESPEC='date' for date only (the default),
                            'hours', 'minutes', 'seconds', or 'ns' for date
                            and time to the indicated precision.
  -r, --reference=文件      显示文件指定文件的最后修改时间
  -R, --rfc-2822            以RFC 2822格式输出日期和时间
          例如:2006年8月7日,星期一 12:34:56 -0600
      --rfc-3339=TIMESPEC   output date and time in RFC 3339 format.
                            TIMESPEC='date', 'seconds', or 'ns' for
                            date and time to the indicated precision.
                            Date and time components are separated by
                            a single space: 2006-08-07 12:34:56-06:00
  -s, --set=STRING          set time described by STRING
  -u, --utc, --universal    print or set Coordinated Universal Time (UTC)
      --help    显示此帮助信息并退出
      --version         显示版本信息并退出

给定的格式FORMAT 控制着输出,解释序列如下:

  %%    一个文字的 %
  %a    当前locale 的星期名缩写(例如: 日,代表星期日)
  %A    当前locale 的星期名全称 (如:星期日)
  %b    当前locale 的月名缩写 (如:一,代表一月)
  %B    当前locale 的月名全称 (如:一月)
  %c    当前locale 的日期和时间 (如:2005年3月3日 星期四 23:05:25)
  %C    世纪;比如 %Y,通常为省略当前年份的后两位数字(例如:20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

当然,我们也可以使用 man 命令来查看

[root@localhost ~]# man date
1

搜索特定的指令文件

[root@localhost ~]# man -f date
date (1)             - print or set the system date and time
1
2

可以指定关键词进行搜索,这个显示的

[root@localhost ~]# man -k mkdi
mkdir (1)            - make directories
1
2

# infoPage

基本上,into与man的用途其实差不多,都是用来查询指令的用法或者是文件的格式。但是与 man page口气输出一堆信息不同的是, info page则是将文件数据拆成一个一个的段落,每个段落用自己的页面来撰写,并且在各个页面中还有类似网页的『超链接」来跳到各不同的页面中,每个独立的页面也被称为一个节点(node)。所以,你可以将 info page想成是文本模式的网页显示数据啦!

info info
File: info.info,  Node: Top,  Next: Getting Started,  Up: (dir)

Info: An Introduction
*********************

The GNU Project distributes most of its on-line manuals in the "Info
format", which you read using an "Info reader".  You are probably using
an Info reader to read this now.

   There are two primary Info readers: 'info', a stand-alone program
designed just to read Info files (*note What is Info?: (info-stnd)Top.),
and the 'info' package in GNU Emacs, a general-purpose editor.  At

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 简单文本编辑器 nano

我们可以使用nano新建一个文件

nano test.txt
1

软件长下面这样子

image-20210514171947056

image-20210514172022464

我们按ctrl+x 就可以离开了,离开的时候会提示你是否保存

# 正确关机的方法

使用who可以查看谁在线

[root@localhost ~]# who
root     pts/0        2021-05-14 17:19 (192.168.123.119)
root     pts/1        2021-05-14 17:19 (192.168.123.119)
1
2
3

使用 netstat 可以查看网络的联机状态

[root@localhost ~]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0     36 localhost.localdoma:ssh 192.168.123.119:29810   ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34566          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34689          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34706          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34814          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34821          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34544          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34619          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34775          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34590          ESTABLISHED
tcp6       0      0 192.168.123.131:mysql   MI-3.lan:34651          ESTABLISHED
1
2
3
4
5
6
7
8
9
10
11
12
13
14

使用 ps -aux 可以查看使用状态

[root@localhost ~]# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 125600  3596 ?        Ss   5月05   0:04 /usr/lib/systemd/systemd --switched-root 
root         2  0.0  0.0      0     0 ?        S    5月05   0:00 [kthreadd]
1
2
3
4
  • 将数据同步写入硬盘中的指令:sync
  • 惯用的关机指令: shutdown
  • 重新启动,关机: reboot,halt,poweroff

我们可以查看一下shutdown的参数

[root@localhost ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown
1
2
3
4
5
6
7
8
9
10
11
12
13

image-20210514172652305

几个常用的命令

image-20210514172734089

使用 systemctl 进行关机

[root@ study-]# systemctl reboot #系统重新启动
[root@ study-]# systemctl poweroff #系统关机
1
2
编辑 (opens new window)
上次更新: 2021/05/14, 18:03:37
文件权限与目录配置

文件权限与目录配置→

Theme by Vdoing | Copyright © 2021-2021 小游
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式