...
 
Commits (25)
    https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/eb22010920a60261aa0cb54c2ee2763fa3697952 新增章节 2022-01-26T11:36:35+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/3b632c359423569e33098de8fefe962110c3a39b 增加grep 2022-01-27T00:27:36+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/f93c22bec1601c3ff44a71d62fc2cf0e0de619b6 增加awk 2022-01-27T01:10:21+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/06ac494e185fd0b506507c2a762062e92d99827f 增加lsof 2022-01-27T12:00:59+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/8e2060d2aab84d7afaebe8c1be4105a536941654 增加一组实用命令 2022-01-27T16:51:21+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/fc328a5295d272ac7bf1837faf036cff338eaf41 增加一组实用命令 2022-01-27T16:51:35+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/f83c66001c65358a8a5cbe7ce92c273f978eb86f opt keywords_must for linux使用命令 2022-01-27T18:33:37+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/c4aaaf3db37f648ab2fca55cf85bc4e61a515ecd opt keywords_must for linux使用命令 2022-01-27T18:33:51+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/ebc70060f2bf0bf71b78a0cfc15173b9fab10f95 opt keywords_must for linux使用命令 2022-01-27T18:40:17+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/ee546c0049d14641367c43ea29cf456ce2ff96ca 增加Linux实用命令 2022-01-27T20:52:06+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/f23e24dc3de3b43057c985018ca299c2718b013c opt keywords_must for Linux安装 2022-01-28T10:07:49+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/61c378836d593431af9cd11a8be01871c5d1376a opt keywords_must for Linux安装 2022-01-28T10:13:14+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/6df9e44c5dfacced30af54e819e77bf6c493cc77 opt keywords_must for Linux安装 2022-01-28T10:13:49+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/b72bd5c3ff8681baccaff8b9cbb52168b40434e2 opt keywords_must for Linux安装 2022-01-28T10:38:44+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/baa45a60f2c6efcc668e24c4b207f5c062d7b342 opt keywords_must for Linux安装 2022-01-28T10:39:03+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/ce7488b4779d81a9c9b7976523a31fad47b6cb52 opt keywords_must for Linux安装 2022-01-28T10:45:50+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/2e6c1a6c22a7457c5ce484e16313bdc905e9d97a opt keywords_must for Linux安装 2022-01-28T10:51:03+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/41a8a6862172d4d0c536e1a3eda4ffc2e05da3a3 opt keywords_must for Linux安装 2022-01-28T11:25:39+08:00 luxin xinlu.nlp@foxmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/c13929bf850973dbd01f27c0485285fc03480ab0 增加管道 2022-01-28T11:34:45+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/9f55eb46d99c3527f0dc966982724abbb1b37b5d 增加管道+fix1 2022-01-28T11:52:58+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/d830d5bba7638c37e740249fbbd795eb1ae5b498 增加管道+fix2 2022-01-28T11:55:51+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/ac1c9b58fb9125c6001b2c3a3b8a6369f36625d4 增加管道+fix3 2022-01-28T13:18:14+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/9187d899e50624e3a7831309a3d20608e5c2bcdf 增加管道+fix3 2022-01-28T15:23:06+08:00 feilong fanfeilong@outlook.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/47dc5ad1c103ff6aa9cd9d36721acd35c12b238c add img 2022-01-29T22:46:38+08:00 xtao cxxtao@gmail.com https://gitcode.net/tt0928/skill_tree_git_md_linux/-/commit/17f48b905eeb3567c0a584ce3c3eb4d0ed33d994 add install vscode for windows 2022-01-29T22:46:38+08:00 xtao cxxtao@gmail.com
# 极简 Git+VSCode for Mac(3): 安装VSCode并打开Git仓库
1. 打开 https://code.visualstudio.com/ 下载 Windows 版
2. 双击 VSCodeUserSetup-x64-x.yy.z.exe 开始安装
3. 在开始菜单中找到 Visual Studio Code 打开 VSCode
4. 打开VSCode后,通过菜单“文件->打开文件夹”的方式打开 hello_git 目录。
<br/>
如图所示,打开 https://code.visualstudio.com/ 下载 Windows 版:
<br/>
![](./img/vscode_01.png)
<br/>
如图所示,安装 vscode:
<br/>
![](./img/vscode_01.1.png)
![](./img/vscode_01.2.png)
![](./img/vscode_01.3.png)
![](./img/vscode_01.4.png)
![](./img/vscode_01.5.png)
<br/>
如果所示,VSCode里打开了仓库目录(如提示是否信任目录,点击信任)
<br/>
![](./img/vscode_02.png)
<br/>
如图所示,VSCode打开了 hello_git 仓库,点击“README.md”文件并显示
<br/>
![](./img/vscode_03.png)
<br/>
经过上述操作,你已经学会安装VSCode并打开Git仓库了,以下描述错误的是?
## 答案
```bash
VSCode 只能通过菜单 文件->打开文件夹 来打开目标文件夹。
```
## 选项
### A
```bash
VSCode 可以通过菜单 文件->打开文件夹 来打开目标文件夹。
```
### B
```bash
VSCode Windows 版本只需要根据安装向导同意协议并点击下一步即可完成安装。
```
### C
```bash
VSCode 打开目录时候,如果需要提示是否信任,可以点击信任,因为这个目录就是你自己创建的,你决定信任这个文件夹。
```
### D
```bash
VSCode Windows 版本可以在官方网站上免费下载使用。
```
{
"node_id": "gml-21ff39f056a142a4988e5717b93569d2",
"keywords": [
"安装Ubuntu",
"安装CentOS"
],
"keywords_must": [["Ubuntu", "操作系统", "安装"], ["CentOS", "操作系统", "安装"], ["Debian", "操作系统", "安装"], ["RedHat", "操作系统", "安装"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "d97da2090250447e8d8a8b8450631a6d"
}
\ No newline at end of file
# 安装Linux
Linux 有很多不同的发行版。例如,Redhat, Debian, Ubuntu, CentOS, Gentoo, SUSE Linux, Mandriva, Slackware 等。不同的发行版侧重的重点不同。以下描述错误的是?
## 答案
```bash
FreeBSD 也是一个基于Linux内核的操作系统,其性能强劲,适合做服务端Linux操作系统。
```
## 选项
### A
```bash
桌面系统一般选 Ubuntu Linux 系统,它的包管理软件是 apt-get,例如安装 wget: `apt-get install wget`
```
### B
```bash
CentOS是常见的服务端Linux发行版,它的包管理软件是 yum, 例如安装 wget: `yum install wget`
```
### C
```bash
Android 底层也是基于 Linux 操作系统内核,也算一种Linux发行版。
```
{
"node_id": "gml-59cbc635a28b4a758b2070206eab6664",
"keywords": [],
"keywords_must": [["Linux", "命令"]],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "gml-66baba204f5042a79ebc82bc2a26ae32",
"keywords": [],
"keywords_must": [["linux", "grep"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "16d668f7af4b4ef8be31f2bcff53ef86"
}
\ No newline at end of file
# 实用Linux命令掌握20%: grep
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
假设文件`1.txt`的文本如下(可以利用`touch`命令和`vi`命令组合创建):
```bash
1. hello world
2. wold hello
3. nothing is important
4. i like movie movie
hello world
wold hello
nothing is important
i like movie movie
```
`grep` 命令用来查找文本,这里是最常用的几个操作例子:
* 查找文件`1.txt`中含有`"hello"`字符串的行:`grep hello 1.txt`
* 使用正则表达式查找文件`1.txt`中含有数字的行:`grep -E "\d." 1.txt`
* 查找文件`1.txt`中不包含`"hello"`字符串的行:`grep -v hello 1.txt`
* 查找文件`1.txt`中含有`"movie"`字符串的行以及它前面的3行:`grep movie -B 3 1.xt`
* 查找文件`1.txt`中含有`"movie"`字符串的行以及它后面的3行:`grep movie -A 3 1.xt`
* 查找文件`1.txt`中含有`"4."`字符串的行以及它前后3行:`grep 4. -C 3 1.txt`
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`grep`命令。
2. 以下对命令`grep`描述错误的是?
## 答案
```bash
`grep`命令不能对文件夹递归查找,例如
`grep "text" . -r -n`
```
## 选项
### A
```bash
如果要查找包含某个字符串的行的前后3行
可以使用 `grep -C 3 xxx.log` 命令
C 表示 center
```
### B
```bash
`grep`命令的匹配参数默认是普通的通配符
`grep`命令的通过`-E`选项来指定正则表达式匹配
```
### C
```bash
`grep`命令可以通过通配符查找多个文件,例如`grep hello *.txt`
```
1. hello world
2. wold hello
3. nothing is important
4. i like movie movie
hello world
wold hello
nothing is important
i like movie movie
\ No newline at end of file
{
"node_id": "gml-d6688990de744b7fa45a0b473dbeff83",
"keywords": [],
"keywords_must": [["linux", "awk"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "f2f55b2a38144abb9c9e1018b2404233"
}
\ No newline at end of file
# 实用Linux命令掌握20%: awk
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
假设文件`1.txt`的文本如下(可以利用`touch`命令和`vi`命令组合创建):
```bash
1. hello world
2. wold hello
3. nothing is important
4. i like movie movie
hello world
wold hello
nothing is important
i like movie movie
```
`awk` 命令可以用来过滤文本,简单理解就是对文本的每行执行命令`awk`指定的脚本,它的基本命令格式如下:
```bash
awk 'BEGIN{ commands } pattern{ commands } END{ commands }' file
```
其中:
* `'BEGIN{ commands }` 指定最开始执行的脚本
* `pattern{ commands }` 对文件的每一行遍历,判断是否满足`pattern`的模式,如果满足则执行脚本
* `END{ commands }` 指定最后执行的脚本
这里是最常用的几个操作例子:
* 打印“开始”,打印每行,打印“结束”: `awk 'BEGIN{ print "开始" } { print } END{ print "结束" }' 1.txt`
* 打印每行的行号:`awk '{print NR}' 1.txt`
* 打印每行的文本:`awk '{print $0}' 1.txt`
* 打印每行的第1列(默认用空格分离):`awk '{print $1}' 1.txt`
* 打印每行的最后1列(默认用空格分离):`awk '{print $NF}' 1.txt`
* 打印每行的倒数第2列(默认用空格分离):`awk '{print $(NF-1)}' 1.txt`
* 打印每行,并为每行带上行号:`awk '{print NR":",$0}' 1.txt`
* 打印含有序号的行:`awk '/\d./ {print}' 1.txt`
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`awk`命令。
2. 以下对命令`awk`描述错误的是?
## 答案
```bash
打印倒数第2列的命令是:
`awk '{print (NF-1)}' 1.txt`
```
## 选项
### A
```bash
打印倒数第2列的命令是:
`awk '{print $(NF-1)}' 1.txt`
```
### B
```bash
`BEGIN{commands}`是可以省略的
`END{commands}`是可以省略的
```
### C
```bash
打印倒数第4列的命令是:
`awk '{print $4}' 1.txt`
```
1. hello hello world
2. wold hello hello
3. nothing is important
4. i like movie movie
hello hello world
wold hello hello
nothing is important
i like movie movie
\ No newline at end of file
{
"node_id": "gml-950dfde5ccf94f15a5316cabdfa72da4",
"keywords": [],
"keywords_must": [["linux", "sed"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "69b3c767a6ff414b9fba647f71a05cec"
}
\ No newline at end of file
# 实用Linux命令掌握20%: sed
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
假设文件`1.txt`的文本如下(可以利用`touch`命令和`vi`命令组合创建):
```bash
1. hello hello world
2. wold hello hello
3. nothing is important
4. i like movie movie
hello hello world
wold hello hello
nothing is important
i like movie movie
```
`sed` 命令可以用来替换文本行、删除文本行,例子如下:
* 查找并替换每行第一个`"hello"``"你好"``sed 's/hello/你好/' 1.txt`
* 查找替换每行中所有的`"hello"``"你好"``sed 's/hello/你好/g' 1.txt`
* 删除含有`"hello"`的行:`sed '/hello/d' 1.txt`
* 删除第2行:`sed '2d' 1.txt`
* 删除第最后一行:`sed '$d' 1.txt`
* 删除第2行到最后一行:`sed '2,$d' 1.txt`
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`sed`命令。
2. 以下对命令`sed`描述错误的是?
## 答案
```bash
查找并替换每行所有"world""世界"
`sed '/world/世界/g' 1.txt`
```
## 选项
### A
```bash
删除第3行到第5行的命令是:
`sed 3,5d 1.txt`
```
### B
```bash
正则表达式里:'^' 表示行开头
正则表达式里:'\s' 表示空格
正则表达式里:'$' 表示行末
那么,删除空行命令是:
`sed '/^\s*$/d' 1.txt`
```
### C
```bash
查找并替换每行所有"world""世界"
`sed 's/world/世界/g' 1.txt`
```
{
"node_id": "gml-df258842dc7544c599464bc3b4dd69fb",
"keywords": [],
"keywords_must": [["linux", "lsof"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "2610bfc69aa347e99c96b17541788b8e"
}
\ No newline at end of file
# 实用Linux命令掌握20%: lsof
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
命令`lsof` 有很多选项,可以用来查看“文件打开的进程”、“进程打开的文件”,“进程打开的TCP或者UDP端口”,“占用了某个TCP或者UDP端口的进程”等。最常用的有如下几个:
* -a:列出打开文件存在的进程;
* -c<进程名>:列出指定进程所打开的文件;
* -d<文件号>:列出占用该文件号的进程;
* -p<进程号>:列出指定进程号所打开的文件;
* -i<条件>:列出符合条件的进程(协议、:端口、 @ip )
`lsof` 经常被用来诊断服务端端口占用情况,进程打开文件等,例子如下:
* 某一个HTTP服务无法启动,例如提示端口8888已被占用,此时可以用:`lsof -i :8888`查看哪个进程占用了8888端口
* 列出进程620所打开的文件:`lsof -p 620`
* 监听tcp链接进程信息:`lsof -i tcp`
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`lsof`命令。
2. 以下对命令`lsof`描述错误的是?
## 答案
```bash
查看占用了3306的进程:
`lsof -i 3306`
```
## 选项
### A
```bash
查看使用了udp协议的进程:
`lsof -i udp`
```
### B
```bash
查看占用了tcp端口9999的进程:
`lsof -i tcp:9999`
```
### C
```bash
查看占用了tcp端口9999的进程,并杀死进程步骤:
* 使用`lsof -i tcp:9999`查看,记住进程号,例如43457
* 使用`kill -9 43457`杀死进程43457
```
{
"node_id": "gml-eb27985ee6c444259e95f2ef7551908c",
"keywords": [],
"keywords_must": [["linux", "df"], ["linux", "du"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "f8de35cbd77040bf80c5b4a6146fb6c8"
}
\ No newline at end of file
# 实用Linux命令掌握20%: df
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
命令`df``du`配合用来查看空间占用情况。
* `df` 命令用来查看磁盘的空间占用情况
* 其中选项`-h`表示以K,M,G为单位,提高信息的可读性
* `du` 命令用来查看目录的空间占用情况,默认会统计到所有子目录
* 其中选项`-h`表示以K,M,G为单位,提高信息的可读性
* 其中选项`-s`表示只显示统计汇总信息
这两个命令都有很多选项,常用的例子是:
* 查看系统磁盘的空间占用情况:`df -h`
* 查看指定目录的空间占用情况:`du /var/ -h`
* 查看指定目录的空间占用情况,只显示汇总信息:`du /var/ -sh`
* 查询指定目录下的直接子目录空间占用情况,只显示汇总信息:`du /var/*/ -sh`
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`df``du`命令。
2. 以下对命令`du``df`描述错误的是?
假设当前目录是`/home/csdn/`,下层目录结构是:
```bash
.
├── Code
├── doc
│ └── 3.txt
└── test
├── 1.txt
└── test
└── 2.txt
```
## 答案
```bash
查看`/home/csdn/`目录下的所有直接子文件夹的空间占用命令是:
`du -h /home/csdn/*/`
```
## 选项
### A
```bash
查看`/home/csdn/`目录下的所有直接子文件夹的空间占用命令是:
`du -sh /home/csdn/*/`
```
### B
```bash
查看`/home/csdn/`目录下的所有子文件夹的空间占用命令是:
`du -h /home/csdn`
```
### C
```bash
查看`/home/csdn/`所在磁盘的空间命令是:
`df -h /home/csdn`
```
{
"node_id": "gml-cf0d7a4a97c34c3ba01732646fcb0617",
"keywords": [],
"keywords_must": [["linux", "tcpdump"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "d3beb3b3c0964942bacf597059f50453"
}
\ No newline at end of file
# 实用Linux命令掌握20%: tcpdump
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
请准备一个Linux主机,如果你本机是Linux环境,或者你的虚拟机是Linux环境都可以。前提准备:
* 安装`tcpdump`命令:`sudo yum install tcpdump`
* 安装`nc`命令:`sudo yum install nc`
<br/>
**例子1,监听指定域名TCP协议数据包**
* 操作一,开始监听指定域名的ip包流量:`tcpdump host csdn.net`
* 操作二,打开浏览器,访问 csdn.net
* 此时,命令行下可以看到客户端和CSDN服务之间的TCP协议IP包,学习网络协议的时候,配合使用很方便。
**例子2,监听来自指定域名的TCP协议包数据包**
* 操作一,开始监听指定域名的ip包流量:`tcpdump src host csdn.net`
* 操作二,打开浏览器,访问 csdn.net
* 此时,命令行下可以看到客户端和CSDN服务之间的TCP协议IP包,学习网络协议的时候,配合使用很方便。
**例子3,监听发送到指定域名的TCP协议包数据包**
* 操作一,开始监听指定域名的ip包流量:`tcpdump dst host csdn.net`
* 操作二,打开浏览器,访问 csdn.net
* 此时,命令行下可以看到客户端和CSDN服务之间的TCP协议IP包,学习网络协议的时候,配合使用很方便。
**例子4,监听指定端口的tcp包**
* 操作一,开始监听:`tcpdump tcp port 80`
* 操作二,打开另外一个终端,使用`nc 192.168.1.1 80`命令访问80端口。
* 此时,tcpdump监听终端下可以看到请求和返回的ip包。同理,如果要监听udp包可以用:`tcpdump udp port 9999`
**例子5,使用 and 组合逻辑**
* 操作一,开始监听指定域名的ip包流量:`tcpdump tcp port 80 and src host 192.168.1.1`
* 操作二,打开另外一个终端,使用`nc 192.168.1.1 80`命令访问80端口。
* 此时,可以看到只输出请求包。
**问题**:以下对命令`tcpdump`描述错误的是?
## 答案
```bash
tcpdump 只能监听 tcp 网络包,不能监听 udp 包
```
## 选项
### A
```bash
使用 tcpdump 可以监听来自指定域名的IP包
使用 tcpdump 可以监听发往指定域名的IP包
```
### B
```bash
使用 tcpdump 可以通过`and`来组合指定监听条件
```
### C
```bash
使用 tcpdump 可以监听某个端口的tcp或者udp包
```
{
"node_id": "gml-260d46ea06e641b68ad7161513dc7be0",
"keywords": [],
"keywords_must": [["linux", "netstat"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "391cf230e41949e2940795f9b7facb4b"
}
\ No newline at end of file
# 实用Linux命令掌握20%: netstat
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
请准备一个Linux主机,如果你本机是Linux环境,或者你的虚拟机是Linux环境都可以。前提准备:
* 安装`netstat`命令:`sudo yum install netstat`
**本节知识**
命令`netstat`用来查看网络状态,选项很多,但是拆开成两个维度后就可以方便组合。
首先,指定查看的范围选项:
* `-a`选项表示查看所有连线中的socket
* `-l`选项表示查看监听中的socket
其次,指定查看的协议类型:
* `-t`选项表示tcp
* `-u`选项表示udp
Linux的大多数命令行选项可以组合,上述两个维度组合后有多种可能:
* 查看所有 socket 状态:`netstat -a`
* 查看所有 tcp socket 状态:`netstat -at`
* 查看所有 udp socket 状态:`netstat -au`
* 查看所有监听中的 socket 状态:`netstat -l`
* 查看所有监听中的 tcp socket 状态:`netstat -lt`
* 查看所有监听中的 udp socket 状态:`netstat -lu`
**问题**:以下对命令`netstat`描述错误的是?
## 答案
```bash
执行命令:`netstat -at`
可以查看所有的 udp socket状态
```
## 选项
### A
```bash
执行命令:`netstat -au`
可以查看所有的 udp socket状态
```
### B
```bash
执行命令:`netstat -lu`
可以查看监听中的 udp socket状态
```
### C
```bash
执行命令:`netstat -lt`
可以查看监听中的 tcp socket状态
```
{
"node_id": "gml-74f056c07abb4af6819b096e2680c6b5",
"keywords": [],
"keywords_must": [["linux", "curl"], ["linux", "wget"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "4a1c9f571a6f4b04a2e2957242249c31"
}
\ No newline at end of file
# 实用Linux命令掌握20%: curl和wget
Linux 命令很多,掌握最实用的一批命令,对于每个实用命令,又只需掌握20%最高频操作。
<br/>
**本节知识**
curl 和 wget 命令都可以用来下载文件和在命令行下发起 http 请求。
wget 常用来下载文件,下载命令用例:
* 下载文件:`wget https://img-home.csdnimg.cn/images/20211024040633.png`
* 在文本文件`1.txt`里配置url列表,每行一个url地址,然后下载:`wget -i 1.txt `
* 文件比较大时,下载中断后要重新下载很麻烦,wget支持断点续传:`wget -c https://img-home.csdnimg.cn/images/20211024040633.png`
curl 常用来测试HTTP请求,用例:
* 执行HTTP Get请求:`curl "https://cn.bing.com"`
* 假设有一个网络API是一个HTTP POST接口,请求的参数和返回的参数都指定为JSON格式,请求的JSON必须指定'user'和'password'字段,那么执行HTTP POST请求登陆,命令格式为:`curl -H "Content-type: application/json" -H "Accept: application/json" -X POST -d '{"user":"xxx","password":"..."}' https://example.net/login`,两个`-H`参数指定HTTP请求头。 `-X POST` 指定了请求方法为POST,`-d`指定了POST请求的参数,这里是一个JSON字符串。
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习上述`df``du`命令。
2. 以下对命令`curl``wget`描述错误的是?
## 答案
```bash
wget 命令不能用来执行 HTTP GET 请求
```
## 选项
### A
```bash
wget 可以通过选项`-c`指定断点续传
```
### B
```bash
curl 可以通过选项`-d`指定请求参数
```
### C
```bash
curl 可以通过选项`-H `设置请求头字段
```
{
"node_id": "gml-e66e052f98274a60b0eb83273cd089e7",
"keywords": [],
"keywords_must": [["linux", "管道"],["linux","pipeline"]],
"keywords_forbid": [],
"children": [],
"export": [
"exercise_01.json",
"exercise_02.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "huanhuilong",
"source": "exercise_01.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "10a7e5e1b1c040efb38ea71f15872ba0"
}
\ No newline at end of file
# 实用Linux命令掌握20%: 管道(pipeline)
我们学习了许多个Linux命令,但是只靠单个命令还只能发挥出Linux命令有限的能力。管道是unix 哲学的核心之一,Linux管道设计源自Unix。通过管道(pipeline)可以组合多个命令来完成一系列的操作。
<br/>
**本节知识**
* 通过管道符号`"|"`,可以组合多个管道命令。
* 例如,使用`cat`命令读取全文,接着使用`grep`命令过滤出含有字符串`"hello"`的行: `cat 1.txt|grep hello`
* 管道符连接的前后两个命令,前面的命令的输出需要是标准输出,后面的命令要需要能接受标准输入
**本节任务**
1. 请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习管道命令。
2. 以下对管道使用错误的是?
## 答案
```bash
命令 `vi` 的输出不是标准输出
从而,可以编辑并过滤文本:
`vi test.txt|grep hello`
```
## 选项
### A
```bash
`ll`命令可以显示目录下的文件信息,每个文件一行
`wc -l`命令可以统计行数
那么,统计目录下文件个数的管道命令组合是:
`ll|wc -l`
```
### B
```bash
`tail -f`命令可以监控某个日志文件的最新增加的日志
那么,可以监控日志文件里最新增加的含有"Error"的日志
`tail -f 1.log|grep Error`
```
### C
```bash
`sort` 命令可以对文本行排序
那么,可以搜索并排序结果
`grep hello *.log|sort`
```
{
"type": "code_options",
"author": "softwareteacher",
"source": "exercise_02.md",
"notebook_enable": false,
"depends": [],
"exercise_id": "bfb2721539e54164b330744a5b4cc1fa"
}
\ No newline at end of file
# 如何用 awk sed 命令统计一个 Unix/Linux 系统中文件大小的分布情况?
![](https://img-ask.csdnimg.cn/upload/1617766280958.jpg?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
<br/>
**问题**
<br/>
[SoftwareTeacher](https://blog.csdn.net/SoftwareTeacher?type=blog)看了《Unix 传奇》一书,想起很久以前读 Unix 文件系统设计思想的时候,里面提到Unix 的很多文件大小在 4K 以下。他提了一个问题
<br/>
“怎么能用Unix 的awk, sed 和其它 shell 命令统计出你当前 Unix/Linux 系统上 所有文件大小的分布情况? (小于1K, 1K - 4K, 4K - 1M, 1M - 10M, 10M - 1G, 1G 以上)”
<br/>
<br/>
**本节任务**
<br/>
请在[线上Linux环境](https://edu.csdn.net/lab/36675?targetLesson=2692)里练习命令。
<br/>
下面是基本实现思路:
<br/>
1. 使用命令列出目录下的所有文件信息
2. 使用命令过滤出文件名和文件大小的列
3. 使用命令统计不同文件大小的个数并计算百分比打印
4. 使用管道把上述1/2/3组合起来
<br/>
以下代码根据一位回答者[Brentbin](https://blog.csdn.net/Brentbin?type=ask)的实现改编,以下实现正确的是?
## 答案
```bash
ls -Rla | awk '{print $9, $5}' | awk '
BEGIN{
size[0] = " 0K-1K"
size[1] = " 1K-4K"
size[2] = " 4K-1M"
size[3] = " 1M-10M"
size[4] = "10M-1G"
size[5] = " 1G+ "
total = 0
}
($2 <= 1024) {a[0]++}
(1024 < $2 && $2 <= 4096) {a[1]++}
(4096 < $2 && $2 <= 1048576) {a[2]++}
(1048576 < $2 && $2 <= 10485760) {a[3]++}
(10485760 < $2 && $2 <= 1073741824) {a[4]++}
(1073741824 < $2 ) {a[5]++}
{total++}
END {
for(i=0;i<length(a);++i)
print size[i], "文件个数:", a[i], "百分比:", (a[i]/total)*100,"%"
}'
```
## 选项
### A
```bash
ls -Rla | awk '{print $9, $5}' | awk '
BEGIN{
size[0] = " 0K-1K"
size[1] = " 1K-4K"
size[2] = " 4K-1M"
size[3] = " 1M-10M"
size[4] = "10M-1G"
size[5] = " 1G+ "
total = 0
}
($2 <= 1024) {a[0]++}
(1024 < $2 && $2 <= 4096) {a[1]++}
(4096 < $2 && $2 <= 1048576) {a[2]++}
(1048576 < $2 && $2 <= 10485760) {a[3]++}
(10485760 < $2 && $2 <= 1073741824) {a[4]++}
(1073741824 < $2 ) {a[5]++}
END {
for(i=0;i<length(a);++i)
print size[i], "文件个数:", a[i], "百分比:", (a[i]/total)*100,"%"
}'
```
### B
```bash
ls -Rl | awk '{print $9, $5}' | awk '
BEGIN{
size[0] = " 0K-1K"
size[1] = " 1K-4K"
size[2] = " 4K-1M"
size[3] = " 1M-10M"
size[4] = "10M-1G"
size[5] = " 1G+ "
total = 0
}
($2 <= 1024) {a[0]++}
(1024 < $2 && $2 <= 4096) {a[1]++}
(4096 < $2 && $2 <= 1048576) {a[2]++}
(1048576 < $2 && $2 <= 10485760) {a[3]++}
(10485760 < $2 && $2 <= 1073741824) {a[4]++}
(1073741824 < $2 ) {a[5]++}
{total++}
END {
for(i=0;i<length(a);++i)
print size[i], "文件个数:", a[i], "百分比:", (a[i]/total)*100,"%"
}'
```
### C
```bash
ls -Rla | awk '{print $9, $5}' | awk '
BEGIN{
size[0] = " 0K-1K"
size[1] = " 1K-4K"
size[2] = " 4K-1M"
size[3] = " 1M-10M"
size[4] = "10M-1G"
size[5] = " 1G+ "
total = 0
}
($2 <= 1024) {a[0]++}
(1024 < $2 && $2 <= 4096) {a[1]++}
(4096 < $2 && $2 <= 1048576) {a[2]++}
(1048576 < $2 && $2 <= 10485760) {a[3]++}
(10485760 < $2 && $2 <= 1073741824) {a[4]++}
{total++}
END {
for(i=0;i<length(a);++i)
print size[i], "文件个数:", a[i], "百分比:", (a[i]/total)*100,"%"
}'
```
### D
```bash
ls -Rla | awk '{print $9, $4}' | awk '
BEGIN{
size[0] = " 0K-1K"
size[1] = " 1K-4K"
size[2] = " 4K-1M"
size[3] = " 1M-10M"
size[4] = "10M-1G"
size[5] = " 1G+ "
total = 0
}
($2 <= 1024) {a[0]++}
(1024 < $2 && $2 <= 4096) {a[1]++}
(4096 < $2 && $2 <= 1048576) {a[2]++}
(1048576 < $2 && $2 <= 10485760) {a[3]++}
(10485760 < $2 && $2 <= 1073741824) {a[4]++}
(1073741824 < $2 ) {a[5]++}
{total++}
END {
for(i=0;i<length(a);++i)
print size[i], "文件个数:", a[i], "百分比:", (a[i]/total)*100,"%"
}'
```
{
"node_id": "gml-18e8d5ee32d843b6a6ad32b311b271ff",
"keywords": [],
"keywords_must": ["linux"],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -687,14 +687,42 @@
],
"keywords_forbid": []
}
},
{
"Linux安装": {
"node_id": "gml-21ff39f056a142a4988e5717b93569d2",
"keywords": [
"安装Ubuntu",
"安装CentOS"
],
"children": [],
"keywords_must": [
[
"Ubuntu",
"操作系统",
"安装"
],
[
"CentOS",
"操作系统",
"安装"
],
[
"Debian",
"操作系统",
"安装"
],
[
"RedHat",
"操作系统",
"安装"
]
],
"keywords_forbid": []
}
}
],
"keywords_must": [
[
"Linux",
"命令"
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
......@@ -1008,7 +1036,158 @@
"gml高阶": {
"node_id": "gml-ec7eb3a512204261a14eafc36bc55188",
"keywords": [],
"children": [],
"children": [
{
"Linux实用命令": {
"node_id": "gml-18e8d5ee32d843b6a6ad32b311b271ff",
"keywords": [],
"children": [
{
"grep命令": {
"node_id": "gml-66baba204f5042a79ebc82bc2a26ae32",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"grep"
]
],
"keywords_forbid": []
}
},
{
"awk命令": {
"node_id": "gml-d6688990de744b7fa45a0b473dbeff83",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"awk"
]
],
"keywords_forbid": []
}
},
{
"sed命令": {
"node_id": "gml-950dfde5ccf94f15a5316cabdfa72da4",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"sed"
]
],
"keywords_forbid": []
}
},
{
"lsof命令": {
"node_id": "gml-df258842dc7544c599464bc3b4dd69fb",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"lsof"
]
],
"keywords_forbid": []
}
},
{
"df和du命令": {
"node_id": "gml-eb27985ee6c444259e95f2ef7551908c",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"df"
],
[
"linux",
"du"
]
],
"keywords_forbid": []
}
},
{
"tcpdump命令": {
"node_id": "gml-cf0d7a4a97c34c3ba01732646fcb0617",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"tcpdump"
]
],
"keywords_forbid": []
}
},
{
"netstat命令": {
"node_id": "gml-260d46ea06e641b68ad7161513dc7be0",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"netstat"
]
],
"keywords_forbid": []
}
},
{
"cURL和wget命令": {
"node_id": "gml-74f056c07abb4af6819b096e2680c6b5",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"curl"
],
[
"linux",
"wget"
]
],
"keywords_forbid": []
}
},
{
"管道": {
"node_id": "gml-e66e052f98274a60b0eb83273cd089e7",
"keywords": [],
"children": [],
"keywords_must": [
[
"linux",
"管道"
],
[
"linux",
"pipeline"
]
],
"keywords_forbid": []
}
}
],
"keywords_must": [
"linux"
],
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": []
}
......