diff --git "a/Day31-35/31.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md" "b/Day31-35/31.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
index d3f457c428cb651aed5d3f3e40a1d5a908d52fe2..2e319f0296730d021701fbd4b6a1209706a05974 100644
--- "a/Day31-35/31.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
+++ "b/Day31-35/31.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
@@ -92,19 +92,19 @@ Linux系统的命令通常都是如下所示的格式:
1. 获取登录信息 - **w** / **who** / **last**/ **lastb**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# w
+ [root ~]# w
23:31:16 up 12:16, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 182.139.66.250 23:03 4.00s 0.02s 0.00s w
jackfrue pts/1 182.139.66.250 23:26 3:56 0.00s 0.00s -bash
- [root@izwz97tbgo9lkabnat2lo8z ~]# who
+ [root ~]# who
root pts/0 2018-04-12 23:03 (182.139.66.250)
jackfrued pts/1 2018-04-12 23:26 (182.139.66.250)
- [root@izwz97tbgo9lkabnat2lo8z ~]# who am i
+ [root ~]# who am i
root pts/0 2018-04-12 23:03 (182.139.66.250)
- [root@izwz97tbgo9lkabnat2lo8z ~]# who mom likes
+ [root ~]# who mom likes
root pts/0 2018-04-12 23:03 (182.139.66.250)
- [root@izwz97tbgo9lkabnat2lo8z ~]# last
+ [root ~]# last
root pts/0 117.136.63.184 Sun May 26 18:57 still logged in
reboot system boot 3.10.0-957.10.1. Mon May 27 02:52 - 19:10 (-7:-42)
root pts/4 117.136.63.184 Sun May 26 18:51 - crash (08:01)
@@ -128,17 +128,17 @@ Linux系统的命令通常都是如下所示的格式:
3. 查看命令的说明和位置 - **whatis** / **which** / **whereis**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# whatis ps
+ [root ~]# whatis ps
ps (1) - report a snapshot of the current processes.
- [root@izwz97tbgo9lkabnat2lo8z ~]# whatis python
+ [root ~]# whatis python
python (1) - an interpreted, interactive, object-oriented programming language
- [root@izwz97tbgo9lkabnat2lo8z ~]# whereis ps
+ [root ~]# whereis ps
ps: /usr/bin/ps /usr/share/man/man1/ps.1.gz
- [root@izwz97tbgo9lkabnat2lo8z ~]# whereis python
+ [root ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
- [root@izwz97tbgo9lkabnat2lo8z ~]# which ps
+ [root ~]# which ps
/usr/bin/ps
- [root@izwz97tbgo9lkabnat2lo8z ~]# which python
+ [root ~]# which python
/usr/bin/python
```
@@ -202,22 +202,22 @@ Linux系统的命令通常都是如下所示的格式:
8. 重启和关机 - **reboot** / **shutdown**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# shutdown -h +5
+ [root ~]# shutdown -h +5
Shutdown scheduled for Sun 2019-05-26 19:34:27 CST, use 'shutdown -c' to cancel.
- [root@izwz97tbgo9lkabnat2lo8z ~]#
- Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:29:27 CST):
+ [root ~]#
+ Broadcast message from root (Sun 2019-05-26 19:29:27 CST):
The system is going down for power-off at Sun 2019-05-26 19:34:27 CST!
- [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -c
+ [root ~]# shutdown -c
- Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:30:22 CST):
+ Broadcast message from root (Sun 2019-05-26 19:30:22 CST):
The system shutdown has been cancelled at Sun 2019-05-26 19:31:22 CST!
- [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -r 23:58
+ [root ~]# shutdown -r 23:58
Shutdown scheduled for Sun 2019-05-26 23:58:00 CST, use 'shutdown -c' to cancel.
- [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -c
+ [root ~]# shutdown -c
- Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:31:06 CST):
+ Broadcast message from root (Sun 2019-05-26 19:31:06 CST):
The system shutdown has been cancelled at Sun 2019-05-26 19:32:06 CST!
```
@@ -247,19 +247,19 @@ Linux系统的命令通常都是如下所示的格式:
1. 创建/删除空目录 - **mkdir** / **rmdir**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir abc
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir -p xyz/abc
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# rmdir abc
+ [root ~]# mkdir abc
+ [root ~]# mkdir -p xyz/abc
+ [root ~]# rmdir abc
```
2. 创建/删除文件 - **touch** / **rm**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch readme.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch error.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm error.txt
+ [root ~]# touch readme.txt
+ [root ~]# touch error.txt
+ [root ~]# rm error.txt
rm: remove regular empty file ‘error.txt’? y
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm -rf xyz
+ [root ~]# rm -rf xyz
```
- `touch`命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间:
@@ -286,7 +286,7 @@ Linux系统的命令通常都是如下所示的格式:
5. 查看文件内容 - **cat** / **tac** / **head** / **tail** / **more** / **less** / **rev** / **od**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.sohu.com/ -O sohu.html
+ [root ~]# wget http://www.sohu.com/ -O sohu.html
--2018-06-20 18:42:34-- http://www.sohu.com/
Resolving www.sohu.com (www.sohu.com)... 14.18.240.6
Connecting to www.sohu.com (www.sohu.com)|14.18.240.6|:80... connected.
@@ -295,9 +295,9 @@ Linux系统的命令通常都是如下所示的格式:
Saving to: ‘sohu.html’
100%[==================================================>] 212,527 --.-K/s in 0.03s
2018-06-20 18:42:34 (7.48 MB/s) - ‘sohu.html’ saved [212527/212527]
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sohu.html
+ [root ~]# cat sohu.html
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# head -10 sohu.html
+ [root ~]# head -10 sohu.html
@@ -307,12 +307,12 @@ Linux系统的命令通常都是如下所示的格式:
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# tail -2 sohu.html
+ [root ~]# tail -2 sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# less sohu.html
+ [root ~]# less sohu.html
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat -n sohu.html | more
+ [root ~]# cat -n sohu.html | more
...
```
@@ -321,13 +321,13 @@ Linux系统的命令通常都是如下所示的格式:
6. 拷贝/移动文件 - **cp** / **mv**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir backup
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cp sohu.html backup/
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd backup
- [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls
+ [root ~]# mkdir backup
+ [root ~]# cp sohu.html backup/
+ [root ~]# cd backup
+ [root backup]# ls
sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z backup]# mv sohu.html sohu_index.html
- [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls
+ [root backup]# mv sohu.html sohu_index.html
+ [root backup]# ls
sohu_index.html
```
@@ -453,41 +453,41 @@ Linux系统的命令通常都是如下所示的格式:
- **iconv** - 编码转换
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat foo.txt
+ [root ~]# cat foo.txt
grape
apple
pitaya
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat bar.txt
+ [root ~]# cat bar.txt
100
200
300
400
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt
+ [root ~]# paste foo.txt bar.txt
grape 100
apple 200
pitaya 300
400
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt > hello.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 hello.txt
+ [root ~]# paste foo.txt bar.txt > hello.txt
+ [root ~]# cut -b 4-8 hello.txt
pe 10
le 20
aya 3
0
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat hello.txt | tr '\t' ','
+ [root ~]# cat hello.txt | tr '\t' ','
grape,100
apple,200
pitaya,300
,400
- [root@izwz97tbgo9lkabnat2lo8z ~]# split -l 100 sohu.html hello
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png
+ [root ~]# split -l 100 sohu.html hello
+ [root ~]# wget https://www.baidu.com/img/bd_logo1.png
+ [root ~]# file bd_logo1.png
bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html
+ [root ~]# wc sohu.html
2979 6355 212527 sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html
+ [root ~]# wc -l sohu.html
2979 sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.qq.com -O qq.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# iconv -f gb2312 -t utf-8 qq.html
+ [root ~]# wget http://www.qq.com -O qq.html
+ [root ~]# iconv -f gb2312 -t utf-8 qq.html
```
#### 管道和重定向
@@ -497,14 +497,14 @@ Linux系统的命令通常都是如下所示的格式:
例子:查找当前目录下文件个数。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# find ./ | wc -l
+ [root ~]# find ./ | wc -l
6152
```
例子:列出当前路径下的文件和文件夹,给每一项加一个编号。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls | cat -n
+ [root ~]# ls | cat -n
1 dump.rdb
2 mongodb-3.6.5
3 Python-3.6.5
@@ -515,13 +515,13 @@ Linux系统的命令通常都是如下所示的格式:
例子:查找record.log中包含AAA,但不包含BBB的记录的总数
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat record.log | grep AAA | grep -v BBB | wc -l
+ [root ~]# cat record.log | grep AAA | grep -v BBB | wc -l
```
2. 输出重定向和错误重定向 - **\>** / **>>** / **2\>**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt
+ [root ~]# cat readme.txt
banana
apple
grape
@@ -530,8 +530,8 @@ Linux系统的命令通常都是如下所示的格式:
watermelon
pear
pitaya
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme.txt | sort | uniq > result.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat result.txt
+ [root ~]# cat readme.txt | sort | uniq > result.txt
+ [root ~]# cat result.txt
apple
banana
grape
@@ -543,15 +543,15 @@ Linux系统的命令通常都是如下所示的格式:
3. 输入重定向 - **\<**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'hello, world!' > hello.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]#
- Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:05 2018):
+ [root ~]# echo 'hello, world!' > hello.txt
+ [root ~]# wall < hello.txt
+ [root ~]#
+ Broadcast message from root (Wed Jun 20 19:43:05 2018):
hello, world!
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo 'I will show you some code.' >> hello.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]#
- Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:55 2018):
+ [root ~]# echo 'I will show you some code.' >> hello.txt
+ [root ~]# wall < hello.txt
+ [root ~]#
+ Broadcast message from root (Wed Jun 20 19:43:55 2018):
hello, world!
I will show you some code.
```
@@ -561,7 +561,7 @@ Linux系统的命令通常都是如下所示的格式:
下面的命令除了在终端显示命令`ls`的结果之外,还会追加输出到`ls.txt`文件中。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls | tee -a ls.txt
+ [root ~]# ls | tee -a ls.txt
```
#### 别名
@@ -569,20 +569,20 @@ Linux系统的命令通常都是如下所示的格式:
1. **alias**
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# alias ll='ls -l'
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# alias frm='rm -rf'
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ll
+ [root ~]# alias ll='ls -l'
+ [root ~]# alias frm='rm -rf'
+ [root ~]# ll
...
drwxr-xr-x 2 root root 4096 Jun 20 12:52 abc
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm abc
+ [root ~]# frm abc
```
2. **unalias**
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# unalias frm
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# frm sohu.html
+ [root ~]# unalias frm
+ [root ~]# frm sohu.html
-bash: frm: command not found
```
@@ -593,7 +593,7 @@ Linux系统的命令通常都是如下所示的格式:
sed是操作、过滤和转换文本内容的工具。假设有一个名为fruit.txt的文件,内容如下所示。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# cat -n fruit.txt
+ [root ~]# cat -n fruit.txt
1 banana
2 grape
3 apple
@@ -604,7 +604,7 @@ Linux系统的命令通常都是如下所示的格式:
接下来,我们在第2行后面添加一个pitaya。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2a pitaya' fruit.txt
+ [root ~]# sed '2a pitaya' fruit.txt
banana
grape
pitaya
@@ -618,7 +618,7 @@ Linux系统的命令通常都是如下所示的格式:
在第2行前面插入一个waxberry。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2i waxberry' fruit.txt
+ [root ~]# sed '2i waxberry' fruit.txt
banana
waxberry
grape
@@ -630,7 +630,7 @@ Linux系统的命令通常都是如下所示的格式:
删除第3行。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed '3d' fruit.txt
+ [root ~]# sed '3d' fruit.txt
banana
grape
watermelon
@@ -640,7 +640,7 @@ Linux系统的命令通常都是如下所示的格式:
删除第2行到第4行。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2,4d' fruit.txt
+ [root ~]# sed '2,4d' fruit.txt
banana
orange
```
@@ -648,7 +648,7 @@ Linux系统的命令通常都是如下所示的格式:
将文本中的字符a替换为@。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed 's#a#@#' fruit.txt
+ [root ~]# sed 's#a#@#' fruit.txt
b@nana
gr@pe
@pple
@@ -659,7 +659,7 @@ Linux系统的命令通常都是如下所示的格式:
将文本中的字符a替换为@,使用全局模式。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sed 's#a#@#g' fruit.txt
+ [root ~]# sed 's#a#@#g' fruit.txt
b@n@n@
gr@pe
@pple
@@ -674,7 +674,7 @@ Linux系统的命令通常都是如下所示的格式:
假设有一个名为fruit2.txt的文件,内容如下所示。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# cat fruit2.txt
+ [root ~]# cat fruit2.txt
1 banana 120
2 grape 500
3 apple 1230
@@ -685,14 +685,14 @@ Linux系统的命令通常都是如下所示的格式:
显示文件的第3行。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# awk 'NR==3' fruit2.txt
+ [root ~]# awk 'NR==3' fruit2.txt
3 apple 1230
```
显示文件的第2列。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{print $2}' fruit2.txt
+ [root ~]# awk '{print $2}' fruit2.txt
banana
grape
apple
@@ -703,7 +703,7 @@ Linux系统的命令通常都是如下所示的格式:
显示文件的最后一列。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{print $NF}' fruit2.txt
+ [root ~]# awk '{print $NF}' fruit2.txt
120
500
1230
@@ -714,7 +714,7 @@ Linux系统的命令通常都是如下所示的格式:
输出末尾数字大于等于300的行。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{if($3 >= 300) {print $0}}' fruit2.txt
+ [root ~]# awk '{if($3 >= 300) {print $0}}' fruit2.txt
2 grape 500
3 apple 1230
5 orange 400
@@ -727,8 +727,8 @@ Linux系统的命令通常都是如下所示的格式:
1. 创建和删除用户 - **useradd** / **userdel**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z home]# useradd hellokitty
- [root@izwz97tbgo9lkabnat2lo8z home]# userdel hellokitty
+ [root home]# useradd hellokitty
+ [root home]# userdel hellokitty
```
- `-d` - 创建用户时为用户指定用户主目录
@@ -741,7 +741,7 @@ Linux系统的命令通常都是如下所示的格式:
3. 修改密码 - **passwd**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# passwd hellokitty
+ [root ~]# passwd hellokitty
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
@@ -765,16 +765,16 @@ Linux系统的命令通常都是如下所示的格式:
5. 切换用户 - **su**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty
- [hellokitty@izwz97tbgo9lkabnat2lo8z root]$
+ [root ~]# su hellokitty
+ [hellokitty root]$
```
6. 以管理员身份执行命令 - **sudo**。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ ls /root
+ [hellokitty ~]$ ls /root
ls: cannot open directory /root: Permission denied
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ sudo ls /root
+ [hellokitty ~]$ sudo ls /root
[sudo] password for hellokitty:
```
@@ -812,7 +812,7 @@ Linux系统的命令通常都是如下所示的格式:
发送方:
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# write hellokitty
+ [root ~]# write hellokitty
Dinner is on me.
Call me at 6pm.
```
@@ -820,8 +820,8 @@ Linux系统的命令通常都是如下所示的格式:
接收方:
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$
- Message from root@izwz97tbgo9lkabnat2lo8z on pts/0 at 17:41 ...
+ [hellokitty ~]$
+ Message from root on pts/0 at 17:41 ...
Dinner is on me.
Call me at 6pm.
EOF
@@ -829,13 +829,13 @@ Linux系统的命令通常都是如下所示的格式:
10. 查看/设置是否接收其他用户发送的消息 - **mesg**。
- ```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg
- is y
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg n
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg
- is n
- ```
+ ```Shell
+ [hellokitty ~]$ mesg
+ is y
+ [hellokitty ~]$ mesg n
+ [hellokitty ~]$ mesg
+ is n
+ ```
### 文件系统
@@ -872,17 +872,17 @@ Linux系统的命令通常都是如下所示的格式:
1. **chmod** - 改变文件模式比特。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l
+ [root ~]# ls -l
...
-rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod g+w,o+w sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l
+ [root ~]# chmod g+w,o+w sohu.html
+ [root ~]# ls -l
...
-rw-rw-rw- 1 root root 211878 Jun 19 16:06 sohu.html
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# chmod 644 sohu.html
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l
+ [root ~]# chmod 644 sohu.html
+ [root ~]# ls -l
...
-rw-r--r-- 1 root root 211878 Jun 19 16:06 sohu.html
...
@@ -896,12 +896,12 @@ Linux系统的命令通常都是如下所示的格式:
2. **chown** - 改变文件所有者。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l
+ [root ~]# ls -l
...
-rw-r--r-- 1 root root 54 Jun 20 10:06 readme.txt
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# chown hellokitty readme.txt
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l
+ [root ~]# chown hellokitty readme.txt
+ [root ~]# ls -l
...
-rw-r--r-- 1 hellokitty root 54 Jun 20 10:06 readme.txt
...
@@ -914,7 +914,7 @@ Linux系统的命令通常都是如下所示的格式:
1. 列出文件系统的磁盘使用状况 - **df**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# df -h
+ [root ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 5.0G 33G 14% /
devtmpfs 486M 0 486M 0% /dev
@@ -927,7 +927,7 @@ Linux系统的命令通常都是如下所示的格式:
2. 磁盘分区表操作 - **fdisk**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# fdisk -l
+ [root ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
@@ -947,7 +947,7 @@ Linux系统的命令通常都是如下所示的格式:
4. 格式化文件系统 - **mkfs**。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mkfs -t ext4 -v /dev/sdb
+ [root ~]# mkfs -t ext4 -v /dev/sdb
```
- `-t` - 指定文件系统的类型。
@@ -969,7 +969,7 @@ Linux系统的命令通常都是如下所示的格式:
1. 启动vim。可以通过`vi`或`vim`命令来启动vim,启动时可以指定文件名来打开一个文件,如果没有指定文件名,也可以在保存的时候指定文件名。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim guess.py
+ [root ~]# vim guess.py
```
2. 命令模式、编辑模式和末行模式:启动vim进入的是命令模式(也称为Normal模式),在命令模式下输入英文字母`i`会进入编辑模式(Insert模式),屏幕下方出现`-- INSERT --`提示;在编辑模式下按下`Esc`会回到命令模式,此时如果输入英文`:`会进入末行模式,在末行模式下输入`q!`可以在不保存当前工作的情况下强行退出vim;在命令模式下输入`v`会进入可视模式(Visual模式),可以用光标选择一个区域再完成对应的操作。
@@ -1017,14 +1017,14 @@ Linux系统的命令通常都是如下所示的格式:
- 比较多个文件。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim -d foo.txt bar.txt
+ [root ~]# vim -d foo.txt bar.txt
```
![](./res/vim-diff.png)
- 打开多个文件。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim foo.txt bar.txt hello.txt
+ [root ~]# vim foo.txt bar.txt hello.txt
```
启动vim后只有一个窗口显示的是foo.txt,可以在末行模式中输入`ls`查看到打开的三个文件,也可以在末行模式中输入`b `来显示另一个文件,例如可以用`:b 2`将bar.txt显示出来,可以用`:b 3`将hello.txt显示出来。
@@ -1080,7 +1080,7 @@ Linux系统的命令通常都是如下所示的格式:
下面以Nginx为例,演示如何使用yum安装软件。
```Shell
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install nginx
+[root ~]# yum -y install nginx
...
Installed:
nginx.x86_64 1:1.12.2-2.el7
@@ -1093,7 +1093,7 @@ Dependency Installed:
nginx-mod-mail.x86_64 1:1.12.2-2.el7
nginx-mod-stream.x86_64 1:1.12.2-2.el7
Complete!
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum info nginx
+[root ~]# yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
@@ -1111,33 +1111,33 @@ License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
: IMAP protocols, with a strong focus on high concurrency, performance and low
: memory usage.
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -v
+[root ~]# nginx -v
nginx version: nginx/1.12.2
```
移除Nginx。
```Shell
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y remove nginx
+[root ~]# yum -y remove nginx
```
下面以MySQL为例,演示如何使用rpm安装软件。要安装MySQL需要先到[MySQL官方网站](https://www.mysql.com/)下载对应的[RPM文件](https://dev.mysql.com/downloads/mysql/),当然要选择和你使用的Linux系统对应的版本。MySQL现在是Oracle公司旗下的产品,在MySQL被收购后,MySQL的作者重新制作了一个MySQL的分支MariaDB,可以通过yum进行安装。
```Shell
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls
+[root mysql]# ls
mysql-community-client-5.7.22-1.el7.x86_64.rpm
mysql-community-common-5.7.22-1.el7.x86_64.rpm
mysql-community-libs-5.7.22-1.el7.x86_64.rpm
mysql-community-server-5.7.22-1.el7.x86_64.rpm
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y remove mariadb-libs
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y install libaio
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
+[root mysql]# yum -y remove mariadb-libs
+[root mysql]# yum -y install libaio
+[root mysql]#rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
...
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
+[root mysql]#rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
...
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
+[root mysql]#rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
...
-[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
+[root mysql]#rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
...
```
@@ -1146,7 +1146,7 @@ mysql-community-server-5.7.22-1.el7.x86_64.rpm
移除安装的MySQL。
```Shell
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# rpm -qa | grep mysql | xargs rpm -e
+[root ~]# rpm -qa | grep mysql | xargs rpm -e
```
#### 下载解压配置环境变量
@@ -1154,7 +1154,7 @@ mysql-community-server-5.7.22-1.el7.x86_64.rpm
下面以安装MongoDB为例,演示这类软件应该如何安装。
```Shell
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
+[root ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
--2018-06-21 18:32:53-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 52.85.83.16, 52.85.83.228, 52.85.83.186, ...
Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|52.85.83.16|:443... connected.
@@ -1163,8 +1163,8 @@ Length: 100564462 (96M) [application/x-gzip]
Saving to: ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’
100%[==================================================>] 100,564,462 630KB/s in 2m 9s
2018-06-21 18:35:04 (760 KB/s) - ‘mongodb-linux-x86_64-rhel70-3.6.5.tgz’ saved [100564462/100564462]
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip mongodb-linux-x86_64-rhel70-3.6.5.tgz
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.5.tar
+[root ~]# gunzip mongodb-linux-x86_64-rhel70-3.6.5.tgz
+[root ~]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.5.tar
mongodb-linux-x86_64-rhel70-3.6.5/README
mongodb-linux-x86_64-rhel70-3.6.5/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel70-3.6.5/MPL-2
@@ -1183,13 +1183,13 @@ mongodb-linux-x86_64-rhel70-3.6.5/bin/mongod
mongodb-linux-x86_64-rhel70-3.6.5/bin/mongos
mongodb-linux-x86_64-rhel70-3.6.5/bin/mongo
mongodb-linux-x86_64-rhel70-3.6.5/bin/install_compass
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# vim .bash_profile
+[root ~]# vim .bash_profile
...
PATH=$PATH:$HOME/bin:$HOME/mongodb-linux-x86_64-rhel70-3.6.5/bin
export PATH
...
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# source .bash_profile
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod --version
+[root ~]# source .bash_profile
+[root ~]# mongod --version
db version v3.6.5
git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
@@ -1199,7 +1199,7 @@ build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
-[root@iZwz97tbgo9lkabnat2lo8Z ~]# mongo --version
+[root ~]# mongo --version
MongoDB shell version v3.6.5
git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
@@ -1218,20 +1218,20 @@ build environment:
1. 安装Python 3.6。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum install gcc
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip Python-3.6.5.tgz
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf Python-3.6.5.tar
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd Python-3.6.5
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install
+ [root ~]# yum install gcc
+ [root ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
+ [root ~]# gunzip Python-3.6.5.tgz
+ [root ~]# tar -xvf Python-3.6.5.tar
+ [root ~]# cd Python-3.6.5
+ [root ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations
+ [root ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
+ [root ~]# make && make install
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 --version
+ [root ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3
+ [root ~]# python3 --version
Python 3.6.5
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 -m pip install -U pip
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# pip3 --version
+ [root ~]# python3 -m pip install -U pip
+ [root ~]# pip3 --version
```
> 说明:上面在安装好Python之后还需要注册PATH环境变量,将Python安装路径下bin文件夹的绝对路径注册到PATH环境变量中。注册环境变量可以修改用户主目录下的.bash_profile或者/etc目录下的profile文件,二者的区别在于前者相当于是用户环境变量,而后者相当于是系统环境变量。
@@ -1239,14 +1239,14 @@ build environment:
2. 安装Redis-3.2.12。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-3.2.12.tar.gz
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-3.2.12.tar
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd redis-3.2.12
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server --version
+ [root ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz
+ [root ~]# gunzip redis-3.2.12.tar.gz
+ [root ~]# tar -xvf redis-3.2.12.tar
+ [root ~]# cd redis-3.2.12
+ [root ~]# make && make install
+ [root ~]# redis-server --version
Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=5bc5cd3c03d6ceb6
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-cli --version
+ [root ~]# redis-cli --version
redis-cli 3.2.12
```
@@ -1257,34 +1257,34 @@ build environment:
1. 启动防火墙服务。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl start firewalld
+ [root ~]# systemctl start firewalld
```
2. 终止防火墙服务。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl stop firewalld
+ [root ~]# systemctl stop firewalld
```
3. 重启防火墙服务。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl restart firewalld
+ [root ~]# systemctl restart firewalld
```
4. 查看防火墙服务状态。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl status firewalld
+ [root ~]# systemctl status firewalld
```
5. 设置/禁用防火墙服务开机自启。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl enable firewalld
+ [root ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl disable firewalld
+ [root ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
```
@@ -1300,7 +1300,7 @@ build environment:
指定3天以后下午5点要执行的任务。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ at 5pm+3days
+ [root ~]# at 5pm+3days
at> rm -f /root/*.html
at>
job 9 at Wed Jun 5 17:00:00 2019
@@ -1309,30 +1309,30 @@ build environment:
查看待执行的任务队列。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ atq
- 9 Wed Jun 5 17:00:00 2019 a hellokitty
+ [root ~]# atq
+ 9 Wed Jun 5 17:00:00 2019 a root
```
从队列中删除指定的任务。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ atrm 9
+ [root ~]$ atrm 9
```
2. 计划任务表 - **crontab**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# crontab -e
+ [root ~]# crontab -e
* * * * * echo "hello, world!" >> /root/hello.txt
59 23 * * * rm -f /root/*.log
```
- > 说明:输入`crontab -e`命令会打开vim来编辑Cron表达式并指定触发的任务,上面我们定制了两个计划任务,一个是每分钟向/root目录下的hello.txt中追加输出`hello, world!`;另一个是每天23时59分执行删除/root目录下以log为后缀名的文件。如果不知道Cron表达式如何书写,可以参照/etc/crontab文件中的提示(下面会讲到)或者用谷歌搜索一下,也可以使用Cron表达式在线生成器来生成Cron表达式。
+ > 说明:输入`crontab -e`命令会打开vim来编辑Cron表达式并指定触发的任务,上面我们定制了两个计划任务,一个是每分钟向/root目录下的hello.txt中追加输出`hello, world!`;另一个是每天23时59分执行删除/root目录下以log为后缀名的文件。如果不知道Cron表达式如何书写,可以参照/etc/crontab文件中的提示(下面会讲到)或者用搜索引擎找一下“Cron表达式在线生成器”来生成Cron表达式。
和crontab相关的文件在`/etc`目录下,通过修改`/etc`目录下的crontab文件也能够定制计划任务。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd /etc
- [root@iZwz97tbgo9lkabnat2lo8Z etc]# ls -l | grep cron
+ [root ~]# cd /etc
+ [root etc]# ls -l | grep cron
-rw-------. 1 root root 541 Aug 3 2017 anacrontab
drwxr-xr-x. 2 root root 4096 Mar 27 11:56 cron.d
drwxr-xr-x. 2 root root 4096 Mar 27 11:51 cron.daily
@@ -1341,7 +1341,7 @@ build environment:
drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.monthly
-rw-r--r-- 1 root root 493 Jun 23 15:09 crontab
drwxr-xr-x. 2 root root 4096 Jun 10 2014 cron.weekly
- [root@iZwz97tbgo9lkabnat2lo8Z etc]# vim crontab
+ [root etc]# vim crontab
1 SHELL=/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 MAILTO=root
@@ -1364,13 +1364,13 @@ build environment:
1. 安全远程连接 - **ssh**。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ ssh root@120.77.222.217
- The authenticity of host '120.77.222.217 (120.77.222.217)' can't be established.
- ECDSA key fingerprint is SHA256:BhUhykv+FvnIL03I9cLRpWpaCxI91m9n7zBWrcXRa8w.
- ECDSA key fingerprint is MD5:cc:85:e9:f0:d7:07:1a:26:41:92:77:6b:7f:a0:92:65.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added '120.77.222.217' (ECDSA) to the list of known hosts.
- root@120.77.222.217's password:
+ [root ~]$ ssh root@120.77.222.217
+ The authenticity of host '120.77.222.217 (120.77.222.217)' can't be established.
+ ECDSA key fingerprint is SHA256:BhUhykv+FvnIL03I9cLRpWpaCxI91m9n7zBWrcXRa8w.
+ ECDSA key fingerprint is MD5:cc:85:e9:f0:d7:07:1a:26:41:92:77:6b:7f:a0:92:65.
+ Are you sure you want to continue connecting (yes/no)? yes
+ Warning: Permanently added '120.77.222.217' (ECDSA) to the list of known hosts.
+ root@120.77.222.217's password:
```
2. 通过网络获取资源 - **wget**。
@@ -1384,7 +1384,7 @@ build environment:
4. 网络配置工具(旧) - **ifconfig**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ifconfig eth0
+ [root ~]# ifconfig eth0
eth0: flags=4163 mtu 1500
inet 172.18.61.250 netmask 255.255.240.0 broadcast 172.18.63.255
ether 00:16:3e:02:b6:46 txqueuelen 1000 (Ethernet)
@@ -1397,7 +1397,7 @@ build environment:
5. 网络配置工具(新) - **ip**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ip address
+ [root ~]# ip address
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
@@ -1411,7 +1411,7 @@ build environment:
6. 网络可达性检查 - **ping**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ping www.baidu.com -c 3
+ [root ~]# ping www.baidu.com -c 3
PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data.
64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=1 ttl=51 time=36.3 ms
64 bytes from 220.181.111.188 (220.181.111.188): icmp_seq=2 ttl=51 time=36.4 ms
@@ -1426,16 +1426,16 @@ build environment:
8. 查看网络服务和端口 - **netstat** / **ss**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# netstat -nap | grep nginx
+ [root ~]# netstat -nap | grep nginx
```
9. 网络监听抓包 - **tcpdump**。
10. 安全文件拷贝 - **scp**。
- ```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# scp root@1.2.3.4:/root/guido.jpg hellokitty@4.3.2.1:/home/hellokitty/pic.jpg
- ```
+ ```Shell
+ [root ~]# scp root@1.2.3.4:/root/guido.jpg hellokitty@4.3.2.1:/home/hellokitty/pic.jpg
+ ```
11. 文件同步工具 - **rsync**。
@@ -1444,9 +1444,9 @@ build environment:
12. 安全文件传输 - **sftp**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# sftp root@120.77.222.217
- root@120.77.222.217's password:
- Connected to 120.77.222.217.
+ [root ~]# sftp root@1.2.3.4
+ root@1.2.3.4's password:
+ Connected to 1.2.3.4.
sftp>
```
@@ -1473,12 +1473,12 @@ build environment:
1. 查看进程 - **ps**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef
+ [root ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun23 ? 00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0 0 Jun23 ? 00:00:00 [kthreadd]
...
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef | grep mysqld
+ [root ~]# ps -ef | grep mysqld
root 4943 4581 0 22:45 pts/0 00:00:00 grep --color=auto mysqld
mysql 25257 1 0 Jun25 ? 00:00:39 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
```
@@ -1486,7 +1486,7 @@ build environment:
2. 显示进程状态树 - **pstree**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# pstree
+ [root ~]# pstree
systemd─┬─AliYunDun───18*[{AliYunDun}]
├─AliYunDunUpdate───3*[{AliYunDunUpdate}]
├─2*[agetty]
@@ -1512,14 +1512,14 @@ build environment:
3. 查找与指定条件匹配的进程 - **pgrep**。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ pgrep mysqld
+ [root ~]$ pgrep mysqld
3584
```
4. 通过进程号终止进程 - **kill**。
```Shell
- [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ kill -l
+ [root ~]$ 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
@@ -1533,8 +1533,8 @@ build environment:
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
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill 1234
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill -9 1234
+ [root ~]# kill 1234
+ [root ~]# kill -9 1234
```
例子:用一条命令强制终止正在运行的Redis进程。
@@ -1548,13 +1548,13 @@ build environment:
结束名为mysqld的进程。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# pkill mysqld
+ [root ~]# pkill mysqld
```
结束hellokitty用户的所有进程。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# pkill -u hellokitty
+ [root ~]# pkill -u hellokitty
```
> 说明:这样的操作会让hellokitty用户和服务器断开连接。
@@ -1565,8 +1565,8 @@ build environment:
- `&` - 将进程置于后台运行。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod &
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# redis-server
+ [root ~]# mongod &
+ [root ~]# redis-server
...
^Z
[4]+ Stopped redis-server
@@ -1575,7 +1575,7 @@ build environment:
7. 查询后台进程 - **jobs**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs
+ [root ~]# jobs
[2] Running mongod &
[3]- Stopped cat
[4]+ Stopped redis-server
@@ -1584,9 +1584,9 @@ build environment:
8. 让进程在后台继续运行 - **bg**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# bg %4
+ [root ~]# bg %4
[4]+ redis-server &
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs
+ [root ~]# jobs
[2] Running mongod &
[3]+ Stopped cat
[4]- Running redis-server &
@@ -1595,7 +1595,7 @@ build environment:
9. 将后台进程置于前台 - **fg**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# fg %4
+ [root ~]# fg %4
redis-server
```
@@ -1606,15 +1606,15 @@ build environment:
11. 用户登出后进程继续工作 - **nohup**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# nohup ping www.baidu.com > result.txt &
+ [root ~]# nohup ping www.baidu.com > result.txt &
```
12. 跟踪进程系统调用情况 - **strace**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# pgrep mysqld
+ [root ~]# pgrep mysqld
8803
- [root@izwz97tbgo9lkabnat2lo8z ~]# strace -c -p 8803
+ [root ~]# strace -c -p 8803
strace: Process 8803 attached
^Cstrace: Process 8803 detached
% time seconds usecs/call calls errors syscall
@@ -1633,14 +1633,14 @@ build environment:
13. 查看当前运行级别 - **runlevel**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# runlevel
+ [root ~]# runlevel
N 3
```
14. 实时监控进程占用资源状况 - **top**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# top
+ [root ~]# top
top - 23:04:23 up 3 days, 14:10, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
@@ -1661,7 +1661,7 @@ build environment:
2. 查看系统活动信息 - **sar**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# sar -u -r 5 10
+ [root ~]# sar -u -r 5 10
Linux 3.10.0-957.10.1.el7.x86_64 (izwz97tbgo9lkabnat2lo8z) 06/02/2019 _x86_64_ (2 CPU)
06:48:30 PM CPU %user %nice %system %iowait %steal %idle
@@ -1680,7 +1680,7 @@ build environment:
3. 查看内存使用情况 - **free**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# free
+ [root ~]# free
total used free shared buff/cache available
Mem: 1016168 323924 190452 356 501792 531800
Swap: 0 0 0
@@ -1689,7 +1689,7 @@ build environment:
4. 虚拟内存统计 - **vmstat**。
```Shell
- [root@iZ8vba0s66jjlfmo601w4xZ ~]# vmstat
+ [root ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 0 204020 79036 667532 0 0 5 18 101 58 1 0 99 0 0
@@ -1698,7 +1698,7 @@ build environment:
5. CPU信息统计 - **mpstat**。
```Shell
- [root@iZ8vba0s66jjlfmo601w4xZ ~]# mpstat
+ [root ~]# mpstat
Linux 3.10.0-957.5.1.el7.x86_64 (iZ8vba0s66jjlfmo601w4xZ) 05/30/2019 _x86_64_ (1 CPU)
01:51:54 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
@@ -1708,11 +1708,11 @@ build environment:
6. 查看进程使用内存状况 - **pmap**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps
+ [root ~]# ps
PID TTY TIME CMD
4581 pts/0 00:00:00 bash
5664 pts/0 00:00:00 ps
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# pmap 4581
+ [root ~]# pmap 4581
4581: -bash
0000000000400000 884K r-x-- bash
00000000006dc000 4K r---- bash
@@ -1727,7 +1727,7 @@ build environment:
7. 报告设备CPU和I/O统计信息 - **iostat**。
```Shell
- [root@iZwz97tbgo9lkabnat2lo8Z ~]# iostat
+ [root ~]# iostat
Linux 3.10.0-693.11.1.el7.x86_64 (iZwz97tbgo9lkabnat2lo8Z) 06/26/2018 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.79 0.00 0.20 0.04 0.00 98.97
@@ -1739,7 +1739,7 @@ build environment:
8. 显示所有PCI设备 - **lspci**。
```Shell
- [root@izwz97tbgo9lkabnat2lo8z ~]# lspci
+ [root ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
@@ -1756,7 +1756,7 @@ build environment:
9. 显示进程间通信设施的状态 - **ipcs**。
```Shell
- [root@iZ8vba0s66jjlfmo601w4xZ ~]# ipcs
+ [root ~]# ipcs
------ Message Queues --------
key msqid owner perms used-bytes messages
diff --git "a/Day36-40/39.NoSQL\345\205\245\351\227\250.md" "b/Day36-40/39.NoSQL\345\205\245\351\227\250.md"
index e7345ec3817b9bbda8d3f33ecd3e250297df5bc4..c5fbe4cc7f56efc279fbbed4744d6199c0dd08df 100644
--- "a/Day36-40/39.NoSQL\345\205\245\351\227\250.md"
+++ "b/Day36-40/39.NoSQL\345\205\245\351\227\250.md"
@@ -498,7 +498,7 @@ python3
```Python
>>> from pymongo import MongoClient
->>> client = MongoClient('mongodb://120.77.222.217:27017')
+>>> client = MongoClient('mongodb://127.0.0.1:27017')
>>> db = client.school
>>> for student in db.students.find():
... print('学号:', student['stuid'])
diff --git "a/Day41-55/41.\345\277\253\351\200\237\344\270\212\346\211\213.md" "b/Day41-55/41.\345\277\253\351\200\237\344\270\212\346\211\213.md"
index aff16dc87381494023455912cd4e632a3fb6e25d..76a9af06890b1c4edff8f3a9856759803f490634 100644
--- "a/Day41-55/41.\345\277\253\351\200\237\344\270\212\346\211\213.md"
+++ "b/Day41-55/41.\345\277\253\351\200\237\344\270\212\346\211\213.md"
@@ -23,7 +23,7 @@ Web开发的早期阶段,开发者需要手动编写每个页面,例如一
#### HTTP协议
-这里我们稍微费一些笔墨来谈谈上面提到的HTTP。HTTP(超文本传输协议)是构建于TCP(传输控制协议)之上应用级协议,它利用了TCP提供的可靠的传输服务实现了Web应用中的数据交换。按照维基百科上的介绍,设计HTTP最初的目的是为了提供一种发布和接收[HTML](https://zh.wikipedia.org/wiki/HTML)页面的方法,也就是说这个协议是浏览器和Web服务器之间传输的数据的载体。关于这个协议的详细信息以及目前的发展状况,大家可以阅读阮一峰老师的[《HTTP 协议入门》](http://www.ruanyifeng.com/blog/2016/08/http.html)、[《互联网协议入门》](http://www.ruanyifeng.com/blog/2012/05/internet_protocol_suite_part_i.html)系列以及[《图解HTTPS协议》](http://www.ruanyifeng.com/blog/2014/09/illustration-ssl.html)进行了解。下图是我于2009年9月10日凌晨4点在四川省网络通信技术重点实验室用开源协议分析工具Ethereal(抓包工具WireShark的前身)截取的访问百度首页时的HTTP请求和响应的报文(协议数据),由于Ethereal截取的是经过网络适配器的数据,因此可以清晰的看到从物理链路层到应用层的协议数据。
+这里我们稍微费一些笔墨来谈谈上面提到的HTTP。HTTP(超文本传输协议)是构建于TCP(传输控制协议)之上应用级协议,它利用了TCP提供的可靠的传输服务实现了Web应用中的数据交换。按照维基百科上的介绍,设计HTTP最初的目的是为了提供一种发布和接收[HTML](https://zh.wikipedia.org/wiki/HTML)页面的方法,也就是说这个协议是浏览器和Web服务器之间传输的数据的载体。关于这个协议的详细信息以及目前的发展状况,大家可以阅读阮一峰老师的[《HTTP 协议入门》](http://www.ruanyifeng.com/blog/2016/08/http.html)、[《互联网协议入门》](http://www.ruanyifeng.com/blog/2012/05/internet_protocol_suite_part_i.html)系列以及[《图解HTTPS协议》](http://www.ruanyifeng.com/blog/2014/09/illustration-ssl.html)进行了解。下图是我在四川省网络通信技术重点实验室学习和工作期间使用开源协议分析工具Ethereal(抓包工具WireShark的前身)截取的访问百度首页时的HTTP请求和响应的报文(协议数据),由于Ethereal截取的是经过网络适配器的数据,因此可以清晰的看到从物理链路层到应用层的协议数据。
HTTP请求(请求行+请求头+空行+[消息体]):
@@ -33,7 +33,7 @@ HTTP响应(响应行+响应头+空行+消息体):
![](./res/http-response.png)
-> 说明:但愿这两张如同泛黄的照片般的截图能帮助你了解HTTP到底是什么样子的。
+> 说明:这两张图是在2009年9月10日截取的,但愿这两张如同泛黄的照片般的截图能帮助你了解HTTP到底是什么样子的。
### Django概述
@@ -51,6 +51,8 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
1. 检查Python环境:Django 1.11需要Python 2.7或Python 3.4以上的版本;Django 2.0需要Python 3.4以上的版本;Django 2.1需要Python 3.5以上的版本。
+ > 说明:我自己平时使用macOS做开发,macOS和Linux平台使用的命令跟Windows平台有较大的区别,这一点在之前也有过类似的说明,如果使用Windows平台做开发,替换一下对应的命令即可。
+
```Shell
$ python3 --version
```
@@ -75,7 +77,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
$ python3 -m venv venv
$ source venv/bin/activate
```
- > 说明:上面使用了Python自带的venv模块完成了虚拟环境的创建,当然也可以使用其他的工具,例如:virtualenv或pipenv等。要激活虚拟环境,在Windows系统下是通过"venv/Scripts/activate"`执行批处理文件来实现。
+ > 说明:上面使用了Python自带的venv模块完成了虚拟环境的创建,当然也可以使用virtualenv或pipenv这样的工具。要激活虚拟环境,在Windows环境下可以通过"venv/Scripts/activate"执行批处理文件来实现。
4. 更新包管理工具pip。
@@ -99,7 +101,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
或指定版本号来安装对应的Django的版本。
```Shell
- (venv)$ pip install django==1.11
+ (venv)$ pip install django==2.1.8
```
6. 检查Django的版本。
@@ -123,7 +125,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
(venv)$ pip list
```
- 下图展示了Django版本和Python版本的对应关系,如果在安装时没有指定版本号,将自动选择最新的版本(在写作这段内容时,最新的版本是2.0;目前最新的版本已经更新到2.2)。
+ 下图展示了Django版本和Python版本的对应关系,如果在安装时没有指定版本号,将自动选择最新的版本(在写作这段内容时,Django最新的版本是2.2)。
| Django版本 | Python版本 |
| ---------- | ----------------------- |
@@ -143,11 +145,13 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
执行上面的命令后看看生成的文件和文件夹,它们的作用如下所示:
- - `manage.py`: 一个让你用各种方式管理 Django 项目的命令行工具。
- - `oa/__init__.py`:一个空文件,告诉 Python 这个目录应该被认为是一个 Python 包。
- - `oa/settings.py`:Django 项目的配置文件。
- - `oa/urls.py`:Django 项目的 URL 声明,就像你网站的“目录”。
- - `oa/wsgi.py`:作为你的项目的运行在 WSGI 兼容的Web服务器上的入口。
+ - `manage.py`: 一个让你可以管理Django项目的工具程序。
+ - `oa/__init__.py`:一个空文件,告诉Python解释器这个目录应该被视为一个Python的包。
+ - `oa/settings.py`:Django项目的配置文件。
+ - `oa/urls.py`:Django项目的URL声明(URL映射),就像是你的网站的“目录”。
+ - `oa/wsgi.py`:项目运行在WSGI兼容Web服务器上的接口文件。
+
+ > 说明:WSGI全称是Web服务器网关接口,维基百科上给出的解释是“为Python语言定义的[Web服务器](https://zh.wikipedia.org/wiki/%E7%B6%B2%E9%A0%81%E4%BC%BA%E6%9C%8D%E5%99%A8)和[Web应用程序](https://zh.wikipedia.org/wiki/%E7%BD%91%E7%BB%9C%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F)或框架之间的一种简单而通用的接口”。
8. 启动服务器运行项目。
@@ -164,7 +168,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
> 说明2:用于开发的服务器在需要的情况下会对每一次的访问请求重新载入一遍Python代码。所以你不需要为了让修改的代码生效而频繁的重新启动服务器。然而,一些动作,比如添加新文件,将不会触发自动重新加载,这时你得自己手动重启服务器。
- > 说明3:可以通过`python manage.py help`命令查看可用命令列表;在启动服务器时,也可以通过`python manage.py runserver 1.2.3.4:5678`来指定绑定的IP地址和端口。
+ > 说明3:可以通过`python manage.py help`命令查看可用命令列表;在启动服务器时,也可以通过`python manage.py runserver 1.2.3.4:5678`来指定将服务器运行于哪个IP地址和端口。
> 说明4:可以通过Ctrl+C来终止服务器的运行。
@@ -199,14 +203,14 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
执行上面的命令会在当前路径下创建hrs目录,其目录结构如下所示:
- - `__init__.py`:一个空文件,告诉 Python 这个目录应该被认为是一个 Python 包。
+ - `__init__.py`:一个空文件,告诉Python解释器这个目录应该被视为一个Python的包。
- `admin.py`:可以用来注册模型,用于在Django的管理界面管理模型。
- - `apps.py`:当前应用的配置。
+ - `apps.py`:当前应用的配置文件。
- `migrations`:存放与模型有关的数据库迁移信息。
- - `__init__.py`:一个空文件,告诉 Python 这个目录应该被认为是一个 Python 包。
- - `models.py`:存放应用的数据模型,即实体类及其之间的关系(MVC/MVT中的M)。
+ - `__init__.py`:一个空文件,告诉Python解释器这个目录应该被视为一个Python的包。
+ - `models.py`:存放应用的数据模型,即实体类及其之间的关系(MVC/MTV中的M)。
- `tests.py`:包含测试应用各项功能的测试类和测试函数。
- - `views.py`:处理请求并返回响应的函数(MVC中的C,MVT中的V)。
+ - `views.py`:处理请求并返回响应的函数(MVC中的C,MTV中的V)。
2. 修改应用目录下的视图文件views.py。
@@ -240,7 +244,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
```
> 说明:上面使用的`path`函数是Django 2.x中新添加的函数,除此之外还可以使用支持正则表达式的URL映射函数`re_path`函数;Django 1.x中是用名为`url`函数来设定URL映射。
-4. 切换到项目目录,修改该目录下的urls.py文件,对应用中设定的URL进行合并。
+4. 修改项目目录下的urls.py文件,对应用中设定的URL进行合并。
```Shell
(venv) $ vim oa/urls.py
@@ -256,6 +260,8 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
]
```
+ > 说明:上面的代码通过`include`函数将hrs应用中配置URL的文件包含到项目的URL配置中,并映射到`hrs/`路径下。
+
5. 重新运行项目,并打开浏览器中访问。
```Shell
@@ -316,9 +322,7 @@ Django诞生于2003年,它是一个在真正的应用中成长起来的项目
上面通过拼接HTML代码的方式生成动态视图的做法在实际开发中是无能接受的,这一点大家一定能够想到。为了解决这个问题,我们可以提前准备一个模板页,所谓模板页就是一个带占位符的HTML页面,当我们将程序中获得的数据替换掉页面中的占位符时,一个动态页面就产生了。
-我们可以用Django框架中template模块的Template类创建模板对象,通过模板对象的render方法实现对模板的渲染。所谓的渲染就是用数据替换掉模板页中的占位符,当然这里的渲染称为后端渲染,即在服务器端完成页面的渲染再输出到浏览器中,这种做法的主要坏处是当并发访问量较大时,服务器会承受较大的负担,所以今天有很多的Web应用都使用了前端渲染,即服务器只为浏览器提供所需的数据(通常是JSON格式),在浏览器中通过JavaScript获取这些数据并渲染到页面上,这些内容在后面为大家呈现。
-
-Django框架通过shortcuts模块的快捷函数`render`简化了渲染模板的操作,具体的用法如下所示。
+我们可以用Django框架中template模块的Template类创建模板对象,通过模板对象的render方法实现对模板的渲染,在Django框架中还有一个名为`render`的便捷函数可以来完成渲染模板的操作。所谓的渲染就是用数据替换掉模板页中的占位符,当然这里的渲染称为后端渲染,即在服务器端完成页面的渲染再输出到浏览器中,这种做法的主要坏处是当并发访问量较大时,服务器会承受较大的负担,所以今天有很多的Web应用都使用了前端渲染,即服务器只提供所需的数据(通常是JSON格式),在浏览器中通过JavaScript获取这些数据并渲染到页面上,这个我们在后面的内容中会讲到。
1. 先回到manage.py文件所在的目录创建名为templates文件夹。
@@ -359,7 +363,7 @@ Django框架通过shortcuts模块的快捷函数`render`简化了渲染模板的