-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
557 lines (337 loc) · 358 KB
/
atom.xml
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>岂曰无衣的博客</title>
<subtitle>Less is More</subtitle>
<link href="http://ljmeng.site/atom.xml" rel="self"/>
<link href="http://ljmeng.site/"/>
<updated>2024-07-27T13:59:21.000Z</updated>
<id>http://ljmeng.site/</id>
<author>
<name>岂曰无衣</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>Docker的安装、打包和发布</title>
<link href="http://ljmeng.site/posts/32464/"/>
<id>http://ljmeng.site/posts/32464/</id>
<published>2024-07-27T13:59:21.000Z</published>
<updated>2024-07-27T13:59:21.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>本文从零开始介绍Docker安装,打包和发布,记录下中间的踩坑点和解决方法,包括</p><ul><li>Ubuntu上Docker最便捷安装方式</li><li>简单Web项目使用Docker从零开始的镜像基本打包流程</li><li>Docker本地发布失败时,使用Github工作流快速稳定的进行自动镜像发布</li></ul><span id="more"></span><h2 id="安装">安装</h2><h3 id="ubuntu-安装-docker">Ubuntu 安装 Docker</h3><p><strong>安装命令:</strong></p><ol type="1"><li><code>sudo apt install docker.io</code> 安装命令</li><li><code>systemctl status docker</code> 检查 Docker运行状态,显示<code>Active: active (running)</code>即是在正常运行</li><li><code>sudo systemctl start docker</code>如果没有运行,使用当前命令运行 Docker 服务</li><li><code>sudo systemctl enable docker</code> 开机启动 Docker</li><li><code>sudo docker version</code> 查看 Docker 版本</li></ol><p><strong>测试命令:</strong></p><p><code>sudo docker run hello-world</code> 下载 Docker测试镜像,并在容器内执行<code>hello-world</code>样例程序</p><ul><li>如果成功运行显示<code>Hello from Docker!</code>则标识安装成功,同时网络也正常</li><li>如果提示拉取失败等网络错误,则需要参考打包一节中更换镜像源</li></ul><p><strong>非root用户运行Docker</strong></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 改变docker权限控制</span></span><br><span class="line">sudo groupadd docker</span><br><span class="line">sudo usermod -aG docker <span class="variable">$USER</span></span><br><span class="line"><span class="comment"># 重启电脑 或运行下面命令使改动生效</span></span><br><span class="line">newgrp docker</span><br><span class="line"><span class="comment"># 测试效果</span></span><br><span class="line">docker version</span><br><span class="line">docker run hello-world</span><br></pre></td></tr></tbody></table></figure><p><strong>安装 Docker Compose:</strong></p><p>最新版下载地址 <a target="_blank" rel="noopener" href="https://github.com/docker/compose/releases" title="github地址">github.com/docker/compose/releases</a></p><p>一键下载命令,其中<strong>v2.6.1</strong>替换为最新的版本号</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 下载并安装</span></span><br><span class="line">sudo curl -L <span class="string">"https://github.com/docker/compose/releases/download/v2.6.1/docker-compose-<span class="subst">$(uname -s)</span>-<span class="subst">$(uname -m)</span>"</span> -o /usr/local/bin/docker-compose</span><br><span class="line"><span class="comment"># 赋予执行权限</span></span><br><span class="line">sudo <span class="built_in">chmod</span> +x /usr/local/bin/docker-compose</span><br><span class="line"><span class="comment"># 检查版本</span></span><br><span class="line">docker-compose version</span><br></pre></td></tr></tbody></table></figure><h3 id="win10-安装-docker">Win10 安装 Docker</h3><p>直接从<a target="_blank" rel="noopener" href="https://www.docker.com/">官网</a>下载安装</p><p>安装后启动 Docker,仍需要通过命令行运行</p><h2 id="打包">打包</h2><h3 id="更换镜像源">更换镜像源</h3><p>由于国内特殊网络环境,直接拉取Docker很容易失败,故需更换镜像地址加速访问</p><p>推荐使用阿里源,需要注册阿里云账号,<a target="_blank" rel="noopener" href="https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors">镜像地址</a></p><p>参考页面上的说明即可更换镜像地址</p><p>对于Ubuntu可使用如下命令</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sudo <span class="built_in">mkdir</span> -p /etc/docker</span><br><span class="line">sudo <span class="built_in">tee</span> /etc/docker/daemon.json <<-<span class="string">'EOF'</span></span><br><span class="line">{</span><br><span class="line"> <span class="string">"registry-mirrors"</span>: [<span class="string">"https://h06zj4ni.mirror.aliyuncs.com"</span>]</span><br><span class="line">}</span><br><span class="line">EOF</span><br><span class="line">sudo systemctl daemon-reload</span><br><span class="line">sudo systemctl restart docker</span><br></pre></td></tr></tbody></table></figure><h3 id="编写-dockerfile">编写 Dockerfile</h3><p>Dockerfile是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明。</p><p>假设你的FastApi项目结构为</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/root/of/project/</span><br><span class="line">│ Dockerfile</span><br><span class="line">│ requirements.txt </span><br><span class="line">└─app</span><br><span class="line"> │ main.py </span><br></pre></td></tr></tbody></table></figure><p>则可以参考下面的文件编写 Dockerfile</p><figure class="highlight dockerfile"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> python:<span class="number">3.9</span>-slim </span><br><span class="line"><span class="comment"># 拉取一个基础镜像,基于python:3.9-slim 相比于 python:3.9 更精简</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 2、将当前工作目录设置为 /code</span></span><br><span class="line"><span class="comment"># 这是放置 requirements.txt 文件和应用程序目录的地方</span></span><br><span class="line"><span class="keyword">WORKDIR</span><span class="language-bash"> /code</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 3、先复制 requirements.txt 文件</span></span><br><span class="line"><span class="comment"># 由于这个文件不经常更改,Docker 会检测它并在这一步使用缓存,也为下一步启用缓存</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> ./requirements.txt /code/requirements.txt</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 4、运行 pip 命令安装依赖项</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> pip install --no-cache-dir --upgrade -r /code/requirements.txt</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 5、复制 FastAPI 项目代码</span></span><br><span class="line"><span class="keyword">COPY</span><span class="language-bash"> ./app /app</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 6、运行服务</span></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> [<span class="string">"python"</span>, <span class="string">"/app/main.py"</span>]</span></span><br><span class="line"><span class="comment"># 或者</span></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> [<span class="string">"uvicorn"</span>, <span class="string">"app.main:app"</span>, <span class="string">"--host"</span>, <span class="string">"0.0.0.0"</span>, <span class="string">"--port"</span>, <span class="string">"8000"</span>]</span></span><br></pre></td></tr></tbody></table></figure><h3 id="打包和测试">打包和测试</h3><ol type="1"><li><code>docker build -t demo:latest .</code>使用当前目录的Dockerfile进行打包,打包出名字为demo,标签为latest的镜像</li><li><code>docker images</code> 查看本地的镜像列表</li><li><code>docker run -it -p 8000:8000 demo:latest</code>交互式测试运行镜像,并且进行端口转发, 运行后可以通过web访问</li><li><code>docker run -d -p 8000:8000 demo:latest</code>后台运行镜像,会返回完整的镜像id</li><li><code>docker ps -a</code> 查看镜像的运行情况</li><li><code>docker kill 容器ID</code> 终止运行中的容器</li><li><code>docker exec -it 容器ID /bin/bash</code> 进入到容器内部</li><li><code>docker rmi 镜像ID</code> 删除镜像</li><li><code>docker rm 容器ID</code> 删除容器</li></ol><h2 id="发布">发布</h2><p>打标签的命令, 可以给一个镜像打多个不同的标签</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 将 myimage:1.0 打一个新的标签 myimage:latest</span></span><br><span class="line">docker tag myimage:1.0 myimage:latest</span><br><span class="line"></span><br><span class="line"><span class="comment"># 标签可以带项目名前缀 myrepo/,myrepo 换成 dockerhub的用户名,可以用于推送到dockerhub</span></span><br><span class="line">docker tag myimage:1.0 myrepo/myimage:latest</span><br></pre></td></tr></tbody></table></figure><h3 id="本地导出">本地导出</h3><ul><li><code>docker export 1e560fca3906 > demo-latest.tar</code>本地导出发布</li><li><code>docker import demo-latest.tar runoob/ubuntu:v4</code>本地导入</li></ul><h3 id="直接发布到-docker-hub">直接发布到 Docker Hub</h3><p>首先进行登录和授权</p><ol type="1"><li>打开 <a target="_blank" rel="noopener" href="https://hub.docker.com/">hub.docker.com</a>注册相应的账号</li><li>打开 <a target="_blank" rel="noopener" href="https://app.docker.com/settings/personal-access-tokens">Token管理页面</a>生成新的token,给予读写权限</li><li>本地执行命令<code>docker login</code>然后输入账号和Token完成登录</li></ol><p>之后将项目打上<code>username/repo</code>标签后,即可开始发布到镜像到repo</p><ul><li><code>docker push username/repo</code>推送默认标签(latest)的镜像</li><li><code>docker push username/repo:v0.0.4</code>推送标签(v0.0.4)的镜像</li></ul><p>网络良好的情况下,可以直接推送成功。</p><p>但是由于国内特殊网络环境,往往会一直失败,遇到<code>EOF</code>等错误,因此可以使用Github的工作流来完成替代发布</p><h3 id="使用github的工作流完成自动发布">使用Github的工作流完成自动发布</h3><blockquote><p>成品可以参考项目 <a target="_blank" rel="noopener" href="https://github.com/lingjiameng/simple-image-host">simple-image-host</a></p></blockquote><p>本节的目的为,配置好Action,后续每次推送格式为标签<code>v1.0.0</code>时,可以自动打包镜像,然后发布标签为<code>v1.0.0</code>的镜像以及更新标签为<code>latest</code>的镜像。相比于手动发布,配置好后,后续发布操作简单,发布速度很快并且十分稳定。</p><ol type="1"><li>首先将本地项目代码推送到Github</li><li>项目主页打开【Action】</li><li>搜索Docker选择【Docker image】开始配置</li><li>将如下配置文件复制粘贴到工作流配置中,保存并提交,注意其中的<code>your_username/your_image_name</code>替换为自己的Docker Hub项目名</li></ol><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Docker</span> <span class="string">Image</span> <span class="string">CI</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">tags:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'v*'</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">build:</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Docker</span> <span class="string">meta</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">meta</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">docker/metadata-action@v5</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">images:</span> <span class="string">your_username/your_image_name</span></span><br><span class="line"> <span class="bullet">-</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Checkout</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v4</span></span><br><span class="line"> <span class="bullet">-</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Set</span> <span class="string">up</span> <span class="string">QEMU</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">docker/setup-qemu-action@v3</span></span><br><span class="line"> <span class="bullet">-</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Set</span> <span class="string">up</span> <span class="string">Docker</span> <span class="string">Buildx</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">docker/setup-buildx-action@v3</span></span><br><span class="line"> <span class="bullet">-</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Login</span> <span class="string">to</span> <span class="string">Docker</span> <span class="string">Hub</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">docker/login-action@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">${{</span> <span class="string">secrets.DOCKERHUB_USERNAME</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">${{</span> <span class="string">secrets.DOCKERHUB_TOKEN</span> <span class="string">}}</span></span><br><span class="line"> <span class="bullet">-</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Build</span> <span class="string">and</span> <span class="string">push</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">docker/build-push-action@v6</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">context:</span> <span class="string">.</span></span><br><span class="line"> <span class="attr">push:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">tags:</span> <span class="string">${{</span> <span class="string">steps.meta.outputs.tags</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">labels:</span> <span class="string">${{</span> <span class="string">steps.meta.outputs.labels</span> <span class="string">}}</span></span><br></pre></td></tr></tbody></table></figure><ol start="5" type="1"><li><p>将配置文件保存后,我们要配置secrets变量,以让github可以自动发布</p></li><li><p>打开页面【Settings】=>【Secrets andvariables】=>【Actions】</p><ul><li>在【Repositorysecrets】新增变量<code>DOCKERHUB_TOKEN</code>,值为在DockerHub生成的Token</li><li>在【Repositorysecrets】新增变量<code>DOCKERHUB_USERNAME</code>,值为在DockerHub的用户名</li></ul></li><li><p>本地项目打标签<code>git tag v1.0.0</code></p></li><li><p>推送标签到远程 <code>git push --tags</code> 或者<code>git push origin v1.0.0</code></p></li></ol><p><strong>到此大功告成!可以看到工作流成功开始运行</strong></p><p>附上标签其他比较常用的操作命令</p><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">1、git tag --list 列出所有的标签</span><br><span class="line">2、git tag <your_tag_name> 创建一个标签</span><br><span class="line">3、git tag -a <your_tag_name> -m ‘your_tag_description’ 创建一个带有注释的标签</span><br><span class="line">4、git show <your_tag_name> 查看标签信息</span><br><span class="line">5、git ls-remote --tags origin 查看所有的远程标签及commit ID</span><br><span class="line">6、git tag -d <your_tag_name> 删除一个标签</span><br><span class="line">7、git push --delete origin <your_tag_name> 删除远程仓库的标签</span><br><span class="line">8、git push origin <your_tag_name> 推送一个标签到远程</span><br><span class="line">9、git push origin --tags 推送多个本地标签到远程</span><br></pre></td></tr></tbody></table></figure><p></p><h2 id="参考资料">参考资料</h2><blockquote><ul><li><a target="_blank" rel="noopener" href="https://www.51cto.com/article/715086.html">如何在 Ubuntu22.04 LTS 中安装 Docker 和 Docker Compose</a></li><li><a target="_blank" rel="noopener" href="https://ostechnix.com/how-to-run-docker-as-non-root-user-in-linux/">HowTo Run Docker As Non-root User In Linux</a></li><li><a target="_blank" rel="noopener" href="https://cloud.tencent.com/developer/article/1893294">【Docker】从零开始将自己的应用打包到docker镜像</a></li><li><a target="_blank" rel="noopener" href="https://www.runoob.com/docker/docker-command-manual.html">Docker命令大全</a></li><li><a target="_blank" rel="noopener" href="https://github.com/docker/metadata-action">github.com/docker/metadata-action</a></li><li><a target="_blank" rel="noopener" href="https://github.com/docker/build-push-action/">github.com/docker/build-push-action</a></li></ul></blockquote><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>本文从零开始介绍Docker安装,打包和发布,记录下中间的踩坑点和解决方法,包括</p>
<ul>
<li>Ubuntu上Docker最便捷安装方式</li>
<li>简单Web项目使用Docker从零开始的镜像基本打包流程</li>
<li>Docker本地发布失败时,使用Github工作流快速稳定的进行自动镜像发布</li>
</ul></body></html></summary>
<category term="docker" scheme="http://ljmeng.site/categories/docker/"/>
<category term="docker" scheme="http://ljmeng.site/tags/docker/"/>
<category term="linux" scheme="http://ljmeng.site/tags/linux/"/>
<category term="git" scheme="http://ljmeng.site/tags/git/"/>
</entry>
<entry>
<title>Hexo支持本地图片指定宽度</title>
<link href="http://ljmeng.site/posts/80727/"/>
<id>http://ljmeng.site/posts/80727/</id>
<published>2024-07-19T17:00:00.000Z</published>
<updated>2024-07-19T17:00:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><ul><li>在<code>hexo-asset-image-fixed</code>本体图片插件基础上修改,拓展markdown语法</li><li>只需在图片路径后增加<code>?700</code>即可将图片宽度指定为700px,轻松对图片进行放大缩小</li><li>而且不影响markdown本地打开编辑时的预览。配合Hexo-Next主题和FancyBox食用效果更佳</li></ul><span id="more"></span><h2 id="简介-introduction">简介 Introduction</h2><p>项目地址 <a target="_blank" rel="noopener" href="https://github.com/lingjiameng/hexo-image-assistant">hexo-image-assistant</a></p><p>Hexo 图片助手。自动为 hexo 中的资源图片提供绝对路径。扩展的 markdown语法支持轻松指定图片宽度,同时不影响正常的markdown阅读。</p><p>Hexo image assistant. Give asset image in hexo a absolutely pathautomatically. Extended markdown syntax supports easily specifying imagewidth.</p><h2 id="参考-reference">参考 Reference</h2><blockquote><p><a target="_blank" rel="noopener" href="https://github.com/xcodebuild/hexo-asset-image">hexo-asset-image</a></p></blockquote><blockquote><p><a target="_blank" rel="noopener" href="https://www.npmjs.com/package/hexo-asset-image-fixed">hexo-asset-image-fixed</a></p></blockquote><blockquote><p><a target="_blank" rel="noopener" href="https://bobcn.github.io/2018/03/24/hexo_reset_image_size/">Hexo中扩展Markdown语法设置图片的大小</a></p></blockquote><h2 id="使用方法-usage">使用方法 Usage</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-image-assistant --save</span><br></pre></td></tr></tbody></table></figure><h2 id="示例-example">示例 Example</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">note</span><br><span class="line">├── apppicker.jpg</span><br><span class="line">├── logo.jpg</span><br><span class="line">└── rules.jpg</span><br><span class="line">note.md</span><br></pre></td></tr></tbody></table></figure><p>确保 <code>_config.yml</code> 中的<code>post_asset_folder: true</code> 为真。</p><p>只需使用 <code>![logo](note/logo.jpg?400)</code> 即可插入<code>logo.jpg</code> 并将宽度设置为 <code>400</code>。</p><hr><p>Make sure <code>post_asset_folder: true</code> in your<code>_config.yml</code>.</p><p>Just use <code>![logo](note/logo.jpg?400)</code> to insert<code>logo.jpg</code> and set width to <code>400</code>.</p><h2 id="历史-history">历史 History</h2><ul><li>2024-07-20:扩展 markdown 语法支持指定图像宽度 by ljmeng</li><li>2019-04-07:修复标题包含 http/https 等关键字 by CoreJa</li><li>2018-04-18:支持 hexo-abbrlink by xcodebuild</li></ul><hr><ul><li>2024-07-20: Extended markdown syntax supports specifying image widthby ljmeng</li><li>2019-04-07: fix title contains a keyword like http/https byCoreJa</li><li>2018-04-18: support hexo-abbrlink by xcodebuild</li></ul><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><ul>
<li>在<code>hexo-asset-image-fixed</code>本体图片插件基础上修改,拓展markdown语法</li>
<li>只需在图片路径后增加<code>?700</code>即可将图片宽度指定为700px,轻松对图片进行放大缩小</li>
<li>而且不影响markdown本地打开编辑时的预览。配合Hexo-Next主题和FancyBox食用效果更佳</li>
</ul></body></html></summary>
<category term="hexo" scheme="http://ljmeng.site/categories/hexo/"/>
<category term="web" scheme="http://ljmeng.site/tags/web/"/>
<category term="hexo" scheme="http://ljmeng.site/tags/hexo/"/>
</entry>
<entry>
<title>【教程】Lucky配合Cloudflare更安全的访问局域网服务</title>
<link href="http://ljmeng.site/posts/16549/"/>
<id>http://ljmeng.site/posts/16549/</id>
<published>2024-07-19T14:00:00.000Z</published>
<updated>2024-07-19T14:00:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>使用Lucky可以比较安全的访问本地服务,但是仍然存在需要加端口访问、IP会暴露的问题。本教程旨在使用Cloudflare和Lucky配合解决这些问题</p><h2 id="预期效果">预期效果</h2><ol type="1"><li>能够不加端口号,通过子域名访问局域网的各项服务</li><li>公网流量全部HTTPS加密,保证信息传输时不会泄露</li><li>IP地址受CF服务器的保护,域名解析出来的IP为CF服务器的IP</li></ol><span id="more"></span><h2 id="前置要求">前置要求</h2><ol type="1"><li>有<a target="_blank" rel="noopener" href="https://dash.cloudflare.com/">Cloudflare(简称CF)</a>账号,并有CF上购买的域名,其他供应商的域名需要托管到CF后使用,托管可以参考<a target="_blank" rel="noopener" href="https://back2me.cn/skills/cloudflare.html">如何将域名托管到cloudflare</a></li><li>了解<a target="_blank" rel="noopener" href="https://lucky666.cn/">Lucky</a>的基本使用方法,懂得配置局域网Web服务的反向代理</li><li>有动态或者静态的公网IP</li></ol><h2 id="配置方法">配置方法</h2><p><strong>必看前言</strong></p><ul><li><p>假设你购买的域名为<code>example.com</code>,下文中所有的<code>example.com</code>使用时请替换为你自己的域名</p></li><li><p>假设路由器已经配置好端口转发,转发的端口为<code>12345</code>,假设lucky的Web服务监听的端口也为<code>12345</code>,下文所有使用到<code>12345</code>的地方,请替换为你自己使用的端口</p></li></ul><h3 id="第一步配置lucky动态域名">第一步:配置Lucky动态域名</h3><p>打开Lucky的动态域名管理页面,选择添加任务,配置好后的结果如下面左图</p><div class="group-picture"><div class="group-picture-row"><div class="group-picture-column"><img src="/posts/16549/image-20240719001105-5oapzj1.png" alt="image"></div><div class="group-picture-column"><img src="/posts/16549/image-20240719002758-e6r4fl9.png" alt="image"></div></div></div><ol type="1"><li><p>关于左图中①处的Token,需要点击蓝色文字跳转CF操作,记得先右上角先切简体中文,之后按照右图中A,B,C的顺序操作,其中B处选择你要使用的域名。其余确认或继续即可创建好token</p></li><li><p>关于左图中②处的类型,根据你的公网ip类型选择,一般为ipv4</p></li><li><p>关于左图中③处的<code>example.com</code>替换为你要使用的域名</p></li><li><p>配置好后保存,等待DDNS任务同步成功</p></li></ol><h3 id="第二步配置cloudflare的反向代理加密和">第二步:配置Cloudflare的反向代理,加密和</h3><p>登录CF,打开自己管理的网站,记得右上角语言切换为简体中文</p><ol type="1"><li><strong>到【DNS】-【记录】里面把DNS解析的代理打开,这样才能保护IP。</strong>这里只需配置一次即可,后续会保持代理启用状态</li></ol><p><img src="/posts/16549/image-20240719013817-ex7hu6f.png" alt="image" width="700"></p><ol start="2" type="1"><li>到【SSL/TLS】-【概述】切换加密方式为 <code>完全(严格)</code></li></ol><p><img src="/posts/16549/image-20240719020600-4rt1tdj.png" alt="image" width="700"></p><ol start="3" type="1"><li>到【SSL/TLS】-【源服务器】选择创建证书,使用默认配置进行创建,将①中的文本保存为<code>example.com.pem</code>文件,将②中的文本保存为<code>example.com.key</code>文件。可以新建文本文档,粘贴保存,再连带txt后缀将文件名修改为给定的文件名。这两个文件记住保存位置,后续会使用到</li></ol><p><img src="/posts/16549/image-20240719015135-7b2c6gs.png" alt="image" width="700"></p><ol start="4" type="1"><li>到【规则】-【OriginRules】选择创建规则,选择<code>所有传入请求</code>,下面选择<code>重写到</code>端口填写为<code>12345</code>, 部署后启用</li></ol><p><img src="/posts/16549/image-20240719015756-zk1kzcu.png" alt="image" width="700"></p><h3 id="第三步配置lucky的证书和web反向代理">第三步:配置Lucky的证书和Web反向代理</h3><p>登录Lucky的管理页面</p><ol type="1"><li><p>打开【安全管理】,选择【添加证书】</p></li><li><p>其中【证书】选择刚才保存的<code>example.com.pem</code>文件,【Key】选择保存的<code>example.com.key</code>文件,选择好后点击添加</p></li></ol><p><img src="/posts/16549/image-20240719020916-nmz3fae.png" alt="image" width="700"></p><ol start="3" type="1"><li>打开【Web服务】,选择【添加Web服务规则】配置web反向代理服务,举例如下图,其中后端地址更改为你想代理的局域网服务的IP加端口</li></ol><div class="group-picture"><div class="group-picture-row"><div class="group-picture-column"><img src="/posts/16549/image-20240719021713-15ju4ny.png" alt="image"></div><div class="group-picture-column"><img src="/posts/16549/image-20240719021928-3exs13e.png" alt="image"></div></div></div><h2 id="结语">结语</h2><p>恭喜你,到此大功告成!</p><p>直接用<code>https://abc.example.com</code>即可在互联网加密访问你家里的局域网服务。</p><p>PS:后续想添加其他局域网的Web服务,只需在Lucky的【Web服务】配置反向代理即可</p><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>使用Lucky可以比较安全的访问本地服务,但是仍然存在需要加端口访问、IP会暴露的问题。本教程旨在使用Cloudflare和Lucky配合解决这些问题</p>
<h2 id="预期效果">预期效果</h2>
<ol type="1">
<li>能够不加端口号,通过子域名访问局域网的各项服务</li>
<li>公网流量全部HTTPS加密,保证信息传输时不会泄露</li>
<li>IP地址受CF服务器的保护,域名解析出来的IP为CF服务器的IP</li>
</ol></body></html></summary>
<category term="web" scheme="http://ljmeng.site/categories/web/"/>
<category term="web" scheme="http://ljmeng.site/tags/web/"/>
</entry>
<entry>
<title>逆波兰表达式</title>
<link href="http://ljmeng.site/posts/16754/"/>
<id>http://ljmeng.site/posts/16754/</id>
<published>2023-12-26T16:40:00.000Z</published>
<updated>2023-12-26T16:40:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>总结了逆波兰表达式的计算方法和逆波兰表达式的生成方法</p><span id="more"></span><h2 id="定义">定义</h2><p><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%B3%A2%E5%85%B0%E8%A1%A8%E7%A4%BA%E6%B3%95">zh.wikipedia.org/wiki/波兰表达式</a></p><p><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E9%80%86%E6%B3%A2%E5%85%B0%E8%A1%A8%E7%A4%BA%E6%B3%95">zh.wikipedia.org/wiki/逆波兰表达式</a></p><blockquote><p><strong>波兰表示法</strong>(英语:Polishnotation,或<strong>波兰记法</strong>)是一种<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91" title="逻辑">逻辑</a>、<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E7%AE%97%E6%9C%AF" title="算术">算术</a>和<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E4%BB%A3%E6%95%B0" title="代数">代数</a>表示方法,其特点是<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%93%8D%E4%BD%9C%E7%AC%A6" title="操作符">操作符</a>置于<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%93%8D%E4%BD%9C%E6%95%B0" title="操作数">操作数</a>的前面,因此也称做<strong>前缀表示法</strong>。如果操作符的<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E5%85%83%E6%95%B0" title="元数">元数</a>(arity)是固定的,则语法上不需要括号仍然能被无歧义地解析</p><p><strong>逆波兰表示法</strong>(英语:Reverse Polishnotation,缩写<strong>RPN</strong>,或<strong>逆波兰记法</strong>、<strong>逆卢卡西维茨记法</strong>),在逆波兰记法中,所有<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E9%81%8B%E7%AE%97%E5%AD%90" title="运算符">操作符</a>置于<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%93%8D%E4%BD%9C%E6%95%B0" title="操作数">操作数</a>的后面,因此也被称为<strong>后缀表示法</strong>、<strong>后序表示法</strong>^^。逆波兰记法不需要括号来标识操作符的优先级。</p></blockquote><p>对于算式 <code>1+(4-5)/7</code> 可以生成抽象语法树</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">digraph G{</span><br><span class="line">"+" -> 1;</span><br><span class="line">"+" -> "/";</span><br><span class="line">"/" -> "-";</span><br><span class="line">"-" -> 4;</span><br><span class="line">"-" -> 5;</span><br><span class="line">"/" -> 7;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>对语法数分别进行前序遍历,中序遍历和后序遍历可得</p><ol type="1"><li>前序遍历(根,左,右) <code>+1/-457</code>波兰表达式,无需括号,表述无歧义</li><li>中序遍历(左,根,右) <code>1+((4-5)/7)</code>需要根据子树添加括号才能保持正确的句法顺序</li><li>后序遍历(左,右,根) <code>145-7/+</code>逆波兰表达式,无需括号,表述无歧义</li></ol><p><strong>逆波兰表达式计算时可以利用计算机的堆栈结构减少计算机内存访问</strong></p><h3 id="算法简介">算法简介</h3><p>从左向右遍历:</p><ol type="1"><li>遇到数字则入栈</li><li>遇到运算符和操作符则出栈数字并求值,然后将结果再次入栈</li><li>循环步骤1和步骤2直至遍历结束,栈顶就是结果数字</li></ol><p></p><h2 id="普通表达式转逆波兰表达式">普通表达式转逆波兰表达式</h2><p><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/394128427">zhihu:逆波兰表达式和表达式求值/计算器算法</a></p><p><strong>使用队列和堆栈配合即可完成转换</strong></p><h4 id="原理分析">原理分析</h4><p>对于表达式 <code>1+5*4*7-7/2</code> 等效于<code>(1+(((5*4)*7)-(7/2)))</code></p><p>可以理解为每个括号为一颗子树:</p><ul><li>低优先级的运算符是前面高优先级运算符的父节点,也就是划定了高优先级运算符的子树边界,</li><li>同优先级的则采用左结合律,即也是前面节点的父节点,所以<code>5/6*7</code> 结构为<code>((5/6)*7)</code></li></ul><p>其中括号特殊,右括号的优先级最低,左括号的优先级最高,但是配对后消失</p><h3 id="算法简介-1">算法简介</h3><p>初始化一个 队列 (存储最终结果) 和 堆栈(存储中间操作数)</p><p>表达式最外层加上一对括号,对于表达式从左向右遍历</p><ol type="1"><li><p>如果为左括号,则加入堆栈</p></li><li><p>如果为数字,则加入队列尾</p></li><li><p>如果为运算符,则检查堆栈,与堆栈顶的运算符比较优先级</p><ol type="1"><li>如果堆栈为空 或者 当前运算符的优先级更高,则直接入栈</li><li>如果当前运算符的优先级<strong>更低或相同</strong>,则将栈顶运算符出栈并加入队列尾,直到符合条件1,则将当前运算符入栈</li></ol></li><li><p>如果为右括号,则循环检查堆栈顶元素</p><ol type="1"><li>如果不为左括号,将堆栈顶运算符出栈并加入队列尾</li><li>如果为左括号,则终止循环,并将左括号出栈丢弃</li></ol></li></ol><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>总结了逆波兰表达式的计算方法和逆波兰表达式的生成方法</p></body></html></summary>
<category term="algorithm" scheme="http://ljmeng.site/categories/algorithm/"/>
<category term="algorithm" scheme="http://ljmeng.site/tags/algorithm/"/>
</entry>
<entry>
<title>饥荒联机版服务器搭建教程2020版</title>
<link href="http://ljmeng.site/posts/11894/"/>
<id>http://ljmeng.site/posts/11894/</id>
<published>2020-06-25T03:47:25.000Z</published>
<updated>2020-06-25T03:47:25.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>Windows搭建有mod的服务器,附带常用mod合集</p><span id="more"></span><h2 id="服务器搭建12">服务器搭建<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a><a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a></h2><h3 id="获取服务器运行工具">获取服务器运行工具</h3><p>购买正版饥荒游戏后,会附带一个搭建服务器的工具<code>Don't Starve Together Dedicated Server</code>,在Steam库中选择工具即可找到,下载并安装即可。</p><h3 id="获取服务器配置和token">获取服务器配置和token</h3><p>接下来要获取服务器配置和token,首先从Steam启动<code>Don't Starve Together</code>。打开下图中指出的账户界面,第一次打开需要注册并登陆<code>Keli</code>的账号。</p><figure><img src="/posts/11894/main_menu_account_button.thumb.jpg.369fefac935a21acb389eb73fe06946a.jpg" alt="main_menu_account_button.jpg"><figcaption aria-hidden="true">main_menu_account_button.jpg</figcaption></figure><p>绑定完成后,注意先要邮箱激活账号,之后打开<a target="_blank" rel="noopener" href="https://accounts.klei.com/account/game/list">链接</a></p><figure><img src="/posts/11894/image-20200625181007766.png" alt="image-20200625181007766"><figcaption aria-hidden="true">image-20200625181007766</figcaption></figure><p>点击上图中的<code>饥荒联机版的游戏服务器</code>,之后就可以<code>创建或配置服务器</code>,配置完成后点击<code>下载设置</code>下载配置文件到本地。其中最关键的是申请<code>服务器票据</code>,会被存储在<code>cluster_token.txt</code>中。同时要记住这里的服务器名字,通过搜索该名字可以加入服务器。</p><p>将压缩包解压,并将文件夹<code>MyDediServer</code>放到目录<code>文档\Klei\DoNotStarveTogether\</code>下。</p><h3 id="启动服务器">启动服务器</h3><p>进入目录<code>\steam\SteamApps\common\Don't Starve Together Dedicated Server\bin</code>创建文本文档,并改名为<code>startDST.bat</code>。将如下内容复制进其中</p><figure class="highlight powershell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="built_in">start</span> dontstarve_dedicated_server_nullrenderer <span class="literal">-console</span> <span class="literal">-cluster</span> MyDediServer <span class="literal">-shard</span> Master</span><br><span class="line"><span class="built_in">start</span> dontstarve_dedicated_server_nullrenderer <span class="literal">-console</span> <span class="literal">-cluster</span> MyDediServer <span class="literal">-shard</span> Caves</span><br></pre></td></tr></tbody></table></figure><p>双击<code>start.bat</code> 即可成功启动服务器</p><h2 id="服务器添加mod">服务器添加mod</h2><ol type="1"><li>进入目录<code>\steam\SteamApps\common\Don't Starve Together Dedicated Server\mods</code></li><li>打开文件 <code>dedicated_server_mods_setup.lua</code>,在这里可以指定服务器要使用的mod,有两种添加方式,<ul><li>第一种为逐个添加,只需在文件中添加多行<code>--ServerModSetup("123456789")</code>即可,其中数字123456789需要替换为你想添加的mod的id,获取id的方法见下</li><li>第二种为使用mod集合添加,推荐这种方法(只需获取一次id,可自行调整合集来调整mod),添加时只需在文件中添加一行<code>ServerModCollectionSetup("2140527659")</code>,id可替换成其他mod合集id,这里的id(2140527659)可以直接使用,已经集成了我使用的服务器mod</li></ul></li></ol><h3 id="获取mod或者mod合集id方法">获取mod或者mod合集id方法</h3><blockquote><p>注意访问创意工坊获取id可能需要服务器或者梯子,推荐直接使用ServerModCollectionSetup("2140527659")</p></blockquote><ol type="1"><li>打开你想要使用的mod或者mod合集主页</li><li>点击下方的分享按钮或者复制页面链接 <img src="/posts/11894/image-modid.png" alt="分享按钮"></li><li>url中圈出的部分为所要id <img src="/posts/11894/image-modid2.png" alt="分享按钮"></li></ol><h2 id="服务器存档迁移">服务器存档迁移</h2><ol type="1"><li><p>首先找到已有存档,打开<code>文档\Klei\DoNotStarveTogether\</code>,再打开文件名是数字的文件夹,再打开形如<code>Cluster_1</code>的文件(创建的存档),复制除了<code>cluster_token.txt</code>外的其他文件</p></li><li><p>将复制的文件粘贴至之前的<code>文档\Klei\DoNotStarveTogether\MyDediServer</code>的文件里,选择替换全部</p></li><li><p>其中<code>cluster.ini</code>可以用文本文档打开,可以修改服务器密码等设置</p></li></ol><h2 id="主要参考资料">主要参考资料</h2><section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"><hr><ol><li id="fn1"><p>官方搭建服务器教程 <a target="_blank" rel="noopener" href="https://forums.kleientertainment.com/forums/topic/64212-dedicated-server-quick-setup-guide-windows/">Windows</a>,<a target="_blank" rel="noopener" href="https://forums.kleientertainment.com/forums/topic/64441-dedicated-server-quick-setup-guide-linux/">linux</a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li><li id="fn2"><p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/440d64cd3ac4">饥荒联机版服务器搭建教程</a><a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li></ol></section></body></html>]]></content>
<summary type="html"><html><head></head><body><p>Windows搭建有mod的服务器,附带常用mod合集</p></body></html></summary>
<category term="game" scheme="http://ljmeng.site/categories/game/"/>
<category term="game" scheme="http://ljmeng.site/tags/game/"/>
</entry>
<entry>
<title>封锁协议 和 数据库的隔离级别</title>
<link href="http://ljmeng.site/posts/28475/"/>
<id>http://ljmeng.site/posts/28475/</id>
<published>2019-12-22T05:00:00.000Z</published>
<updated>2019-12-22T05:00:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>本文回答下面的问题:</p><ul><li>数据库的隔离级别有哪些?</li><li>数据库的隔离级别有什么效果?或者说每个隔离级别解决的问题?</li><li>封锁协议有哪些?</li><li>数据库的隔离级别和封锁协议的关系?</li></ul><span id="more"></span><h2 id="数据隔离级别概念缘起">数据隔离级别概念缘起</h2><p>数据库的基本目标为无论什么情况下,都要保持数据的一致性,而为了达成这一目标,事务处理必须确保ACID性质,即:</p><ul><li>原子性(Atomic) => 数据库恢复机制</li><li>一致性(Consistency) => 事务处理的目标</li><li>隔离性(Isolation) => 并发控制机制</li><li>持久性(Durability) => 数据库恢复机制</li></ul><p><strong>隔离级别</strong>对应的概念正是<strong>隔离性</strong>,所以这是一个与并发控制相关的概念。一个良好的隔离级别应该是每个事务在执行时感觉不到任何其他事务的影响。</p><h2 id="数据隔离性应对的问题">数据隔离性应对的问题</h2><p>显然当事务并发时会产生很多数据不一致的问题,归结起来有三类不一致性:</p><ul><li>丢失修改 Lost Update</li><li>读脏数据 Dirty Read</li><li>不可重复读 Non-repeatable Read</li></ul><p>但实际操作起来,由于隔离的粒度不同,还有一类不一致性,即:</p><ul><li>幻读 Phantoms</li></ul><p>值得提一下的是,幻读和不可重复读的概念很接近,都是两次查询(读取)操作结果不同,而不一样的是:幻读的条件更特殊,幻读指的是记录的条数变了,当记录条数不变,仅仅内容改变时不是幻读。<strong>幻读属于不可重复读的一种情况</strong></p><p>例子:</p><ul><li>某事务第一次查询某人的存款余额是100,之后其他事务修改了余额,再次读取时余额不再是100,这就是不可重复读,但不是幻读。</li><li>某事务查询所有存款余额大于100的人,第一次查询只有一个人,之后其他事务插入了另外一个余额大于100的记录,再次查询,变成了两个人,这就是幻读,也是不可重复读。</li></ul><h2 id="数据库的隔离级别定义">数据库的隔离级别定义</h2><p>数据库的隔离级别分为四层,即:</p><ul><li>串行化 Serializable</li><li>可重复读 Repeatable Read</li><li>读已提交 Read Committed</li><li>读未提交 Read Uncommitted</li></ul><p>而这四个概念的定义是通过何时释放锁以及何时释放锁来定义的(也有用时间戳机制来描述的):<strong>注意下列加锁操作都是要做什么操作,就加对应操作的锁,比方说读操作就加读锁,而不需要考虑接下来要进行写操作而在读的时候加写锁的情况。</strong></p><p><strong>1. 串行化</strong>最高的隔离级别。对于基于锁的并发控制数据库实现:串行化要求<strong>读锁和写锁(根据所选数据获取)在事务结束的时候释放</strong>。同时当使用带有范围条件<code>where</code>的<code>SELECT</code>语句查询时,要求增加相应的范围锁(例如使用<code>select * from t where val>10 and val < 15</code>查询后,会增加相应的<strong>范围锁</strong>,其他事务插入<code>val</code>在这个范围的数据是不被允许的)。</p><p><strong>2.可重复读</strong>对于基于锁的并发控制数据库实现:要求<strong>读锁和写锁(根据所选数据获取)在事务结束的时候释放</strong>。但是<strong>不管理范围锁</strong>。</p><p><strong>3.读已提交</strong>对于基于锁的并发控制数据库实现:要<strong>写锁(根据所选数据获取)在事务结束的时候释放,读锁在<code>select</code>执行结束后立即释放</strong>。这一级别同样不管理范围锁。</p><p><strong>4.读未提交</strong> 对于这一层级,完全不加锁。</p><p>到这里我们就可以得出如下结论的表格:</p><figure><img src="/posts/28475/70034e19.png" alt="70034e19.png"><figcaption aria-hidden="true">70034e19.png</figcaption></figure><p>其实这个表格中一些问题的避免是和封锁方法是对应的:</p><ul><li>范围锁可以避免<strong>幻读</strong>,</li><li>读锁和写锁在事务结束时释放可以避免<strong>丢失修改,不可重复度</strong></li><li>写锁在事务结束时释放,申请读锁并在之后释放可以避免<strong>读脏数据</strong></li></ul><h2 id="数据库封锁协议">数据库封锁协议</h2><p>为了定义并发控制的解决策略,引入了串行化和可串行化的概念。为了达到可串行化调度,就有了一系列的控制方法。其中比较好的控制协议就是通过锁的控制来实现的,这就引入了一系列的封锁协议:</p><ul><li>一级封锁协议</li><li>二级封锁协议</li><li>三级封锁协议</li><li>两阶段封锁协议</li><li>一次封锁协议</li></ul><p>封锁协议是通用的协议,是编程人员编码或者设计的规范。</p><p>它们的定义如下:</p><blockquote><p>一级封锁协议:事务T在修改数据R之前必须先对其加X锁,直到事务结束才释放。</p></blockquote><blockquote><p>二级封锁协议:一级封锁协议加上事务T在读取数据R之前必须先对其加S锁,读完后方可释放S锁。</p></blockquote><blockquote><p>三级封锁协议:一级封锁协议加上事务T在读取数据R之前必须先对其加S锁,直到事务结束才释放。</p></blockquote><blockquote><p>两阶段封锁协议:①在对任何数据进行读、写操作之前,首先要申请并获得对该数据的封锁。②在释放一个封锁之后,事务不再申请和获得其它任何封锁。</p></blockquote><blockquote><p>一次封锁协议: 一次将所有要使用的数据全部加锁</p></blockquote><p>其中事务结束包括正常结束(COMMIT)和非正常结束(ROLLBACK)</p><p>通过定义我们貌似可以发现,封锁协议和数据库隔离级别<strong>看似</strong>有如下对应关系:</p><ul><li>二级封锁协议 => 读已提交隔离级别</li><li>三级封锁协议 => 可重复读隔离级别</li></ul><p><strong>但实际上并不存在对应关系</strong>根本原因出现在封锁协议中的<strong>在数据修改前加锁</strong>,指的是<code>Read(A)</code>和<code>Write(A)</code>绑定在一起考虑,虽然具体的修改操作发生在<code>Write(A)</code>时,但是在<code>Read(A)</code>的时候就要加上写锁。而数据库的隔离级别不会提前加锁。另外两者的主体也是不一样的,在隔离层级策略下会出现锁升级的情况(这其实也是因为数据库无法知道操作者接下来的操作是什么导致的,如果知道可能在一开始就会加上写锁保护)。</p><h2 id="一些额外的问题">一些额外的问题</h2><h3 id="为什么封锁协议和隔离级别看着定义一样实际效果却不同">为什么封锁协议和隔离级别看着定义一样,实际效果却不同?</h3><p>在封锁协议中<strong>Read(A)和Write(A)要绑定认为是一个写操作,开始就要加写锁</strong>,对于之前提到的四种数据一致性问题,我们可以发现:</p><ul><li>一级封锁协议<del>什么都不能保证</del> 保证不丢失修改</li><li>二级封锁协议可以保证不读脏数据 也保证不丢失修改</li><li>三级封锁协议则可以保证不读脏数据,可重复读,不丢失修改,<del>但是不能解决幻读</del></li></ul><p>对于一二级封锁协议的反例如下: <img src="/posts/28475/5d745f01.png" alt="5d745f01.png"><strong>而这个反例也是不存在的</strong>,因为封锁协议要求T1在<code>Read(A)</code>的时候就要加写锁。</p><h3 id="part-2">Part 2</h3><p>此外由于存在幻读现象,那么三级封锁协议和两阶段封锁协议是否还是可串行化的?</p><p><strong>仍然是可串行化的</strong>,幻读本质是封锁粒度的问题,不过当我们理解封锁协议加锁时,应该更好的理解封锁协议中所说的封锁操作对象的含义,随着访问对象的粒度而调整封锁对象的粒度,比如<strong><code>Select</code>范围选择时,应该对表加锁</strong>。</p><h3 id="part-3">Part 3</h3><p>封锁协议之间的包含关系? <img src="/posts/28475/e23f91e5.png" alt="e23f91e5.png"></p><h2 id="参考资料">参考资料</h2><blockquote><p><a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Isolation_(database_systems)">Isolation(database systems) - Wikipedia</a></p></blockquote><blockquote><p><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E4%B8%89%E7%BA%A7%E5%8A%A0%E9%94%81%E5%8D%8F%E8%AE%AE/1148391">三级加锁协议_百度百科</a></p></blockquote></body></html>]]></content>
<summary type="html"><html><head></head><body><p>本文回答下面的问题:</p>
<ul>
<li>数据库的隔离级别有哪些?</li>
<li>数据库的隔离级别有什么效果?或者说每个隔离级别解决的问题?</li>
<li>封锁协议有哪些?</li>
<li>数据库的隔离级别和封锁协议的关系?</li>
</ul></body></html></summary>
<category term="database" scheme="http://ljmeng.site/categories/database/"/>
<category term="database" scheme="http://ljmeng.site/tags/database/"/>
</entry>
<entry>
<title>Java 与 MySQL 开发环境配置</title>
<link href="http://ljmeng.site/posts/63260/"/>
<id>http://ljmeng.site/posts/63260/</id>
<published>2019-12-13T12:15:00.000Z</published>
<updated>2019-12-13T12:15:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>已经安装完MySQL 已经安装完Java 版本要求 java 1.8.0.144</p><h2 id="安装connector">安装connector</h2><p>下载地址 <a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/connector/j/">MySQL:: Download Connector/J</a> 下载时,Windows 用户选择<code>Platform Independent</code>版本,下载好后,直接解压,并将<code>mysql-connector-java-x.x.x.jar</code>复制到jre 目录 <code>C:\Program Files\Java\jre1.8.0_144\lib\ext</code> 下.</p><span id="more"></span><h2 id="配置mysql账户权限创建测试表">配置MySQL账户权限,创建测试表</h2><p>打开 MySQL 命令行终端,先输入密码登陆,之后逐行输入以下指令</p><figure class="highlight sql"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database testdb; <span class="operator">/</span><span class="operator">/</span>创建数据库testdb</span><br><span class="line">use testdb;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> test (`name` <span class="type">varchar</span>(<span class="number">100</span>),<span class="keyword">primary</span> key(`name`)); <span class="operator">/</span><span class="operator">/</span>创建测试表test</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> test (name) <span class="keyword">values</span> ("小明"); </span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> test (name) <span class="keyword">values</span> ("小红");</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> test;</span><br></pre></td></tr></tbody></table></figure><p></p><h2 id="编译并测试java程序">编译并测试java程序</h2><p>注意下面超长 url的参数,出现时区问题加上<code>serverTimezone=UTC</code>,出现root用户登陆问题,尝试加上<code>allowPublicKeyRetrieval=true</code></p><p>创件文件 <code>Main.java</code>,使用<code>javac</code>和<code>java</code> 编译并运行 </p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.sql.PreparedStatement;</span><br><span class="line"><span class="keyword">import</span> java.sql.SQLException;</span><br><span class="line"><span class="keyword">import</span> java.awt.List;</span><br><span class="line"><span class="keyword">import</span> java.sql.Connection;</span><br><span class="line"><span class="keyword">import</span> java.sql.DriverManager; </span><br><span class="line"><span class="keyword">import</span> java.sql.Statement;</span><br><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">import</span> java.sql.ResultSet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Main</span> { </span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(<span class="keyword">final</span> String[] args)</span> { </span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">final</span> <span class="type">Connection</span> <span class="variable">conn</span> <span class="operator">=</span> DriverManager.getConnection(<span class="string">"jdbc:mysql://localhost:3306/dbtest?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true"</span>, <span class="string">"root"</span>,<span class="string">"mljmljmlj"</span>);</span><br><span class="line"> <span class="keyword">final</span> <span class="type">Statement</span> <span class="variable">stat</span> <span class="operator">=</span> conn.createStatement();</span><br><span class="line"> <span class="keyword">final</span> <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">"select * from test;"</span>;</span><br><span class="line"> <span class="keyword">final</span> <span class="type">ResultSet</span> <span class="variable">rs</span> <span class="operator">=</span> stat.executeQuery(sql);</span><br><span class="line"> <span class="keyword">while</span> (rs.next()) { </span><br><span class="line"> System.out.println(rs.getString(<span class="string">"name"</span>)); </span><br><span class="line"> } </span><br><span class="line"> rs.close();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">catch</span>( <span class="keyword">final</span> Exception e ) </span><br><span class="line"> { </span><br><span class="line"> e.printStackTrace(); </span><br><span class="line"> } </span><br><span class="line"> } </span><br><span class="line">} </span><br></pre></td></tr></tbody></table></figure><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>已经安装完MySQL 已经安装完Java 版本要求 java 1.8.0.144</p>
<h2 id="安装connector">安装connector</h2>
<p>下载地址 <a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/connector/j/">MySQL
:: Download Connector/J</a> 下载时,Windows 用户选择
<code>Platform Independent</code>
版本,下载好后,直接解压,并将<code>mysql-connector-java-x.x.x.jar</code>复制到
jre 目录 <code>C:\Program Files\Java\jre1.8.0_144\lib\ext</code> 下.</p></body></html></summary>
<category term="java" scheme="http://ljmeng.site/categories/java/"/>
<category term="java" scheme="http://ljmeng.site/tags/java/"/>
</entry>
<entry>
<title>Java环境配置</title>
<link href="http://ljmeng.site/posts/10305/"/>
<id>http://ljmeng.site/posts/10305/</id>
<published>2019-12-12T12:00:00.000Z</published>
<updated>2019-12-12T12:00:00.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>Java 环境配置摘要</p><h2 id="下载安装jdk">下载安装JDK</h2><p><a target="_blank" rel="noopener" href="https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">官方下载链接</a>,下载对应版本后,双击安装即可</p><h2 id="配置环境变量">配置环境变量</h2><ol type="1"><li>新建<code>JAVA_HOME</code>环境变量,变量值为jdk安装目录,我的电脑上为<code>C:\Program Files\Java\jdk1.8.0_144</code></li><li>新建 <code>CLASSPATH</code> 变量,变量值填写<code>.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar</code></li><li><code>Path</code> 变量增加路径 <code>%JAVA_HOME%\bin</code> 和<code>%JAVA_HOME%\jre\bin</code></li></ol><blockquote><p><strong>PS</strong>以后安装其他版本jdk时只需修改<code>JAVA_HOME</code>环境变量即可</p></blockquote><span id="more"></span><h2 id="检查java安装情况">检查java安装情况</h2><p>打开cmd,输入命令 <code>java -version</code> 和 <code>javac</code>检查</p><p><strong>至此 Java 配置完成</strong></p><h2 id="常用命令">常用命令</h2><p><strong>解决中文输出乱码问题</strong>文件保存为<code>utf-8</code>编码</p><p>编译命令 <code>javac -encoding UTF-8 xx.java</code> 运行命令<code>java '-Dfile.encoding=UTF-8' xx</code>注意第二条命令的参数要加单引号</p><blockquote><p>PS在PowerShell中仍然很可能不正常,可使用chcp命令查看默认编码,若是936(GBK),则需要修改为65001(UTF-8),执行命令<code>chcp 65001</code>即可</p></blockquote><p><code>.java</code> 源代码 -①-> <code>.class</code> jvm字节码-②-> 虚拟机运行及最后打印时的编码</p><ul><li><p>①:jdk使用系统默认编码对java文件进行解码并编译,Win:GBK</p></li><li><p>②:运行时使用系统默认编码进行打印 Win:GBK</p></li></ul><h3 id="对于跨包引用">对于跨包引用</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"># 文件树</span><br><span class="line">package_sample</span><br><span class="line">└─ src</span><br><span class="line"> ├─ hong</span><br><span class="line"> │ └─ Person.java</span><br><span class="line"> │ ming</span><br><span class="line"> │ └─ Person.java</span><br><span class="line"> └─ mr</span><br><span class="line"> └─ jun</span><br><span class="line"> └─ Arrays.java</span><br></pre></td></tr></tbody></table></figure><p>包之间可以相互引用例如<code>hong.Person</code>,<code>mr.jun.Arrays</code></p><p>编译时</p><ol type="1"><li>首先<code>cd ./src</code>,切换至src根目录</li><li>提前创建好要存放输出文件的目录<code>mkdir ../bin</code></li><li>编译需要用到的文件,<code>javac -d ../bin -enconding UTF-8 ./hong/Person.java ./ming/Person.java ./mr/jun/Arrays.java</code></li><li>编译得到输出文件,文件树如下 <figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"># 输出文件的文件树</span><br><span class="line">package_sample</span><br><span class="line">└─ bin</span><br><span class="line"> ├─ hong</span><br><span class="line"> │ └─ Person.class</span><br><span class="line"> │ ming</span><br><span class="line"> │ └─ Person.class</span><br><span class="line"> └─ mr</span><br><span class="line"> └─ jun</span><br><span class="line"> └─ Arrays.class</span><br></pre></td></tr></tbody></table></figure></li><li>执行时,先切换至<code>bin</code>,<code>cd ../bin</code></li><li>执行主程序<code>java '-Dfile.encoding=UTF-8' hong.Person</code></li></ol><p><strong>总结,所有命令如下</strong> </p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 编译</span></span><br><span class="line"><span class="built_in">cd</span> ./src</span><br><span class="line"><span class="built_in">mkdir</span> ../bin</span><br><span class="line">javac -d ../bin -enconding UTF-8 ./hong/Person.java ./ming/Person.java ./mr/jun/Arrays.java</span><br><span class="line"></span><br><span class="line"><span class="comment"># 执行</span></span><br><span class="line"><span class="built_in">cd</span> ../bin</span><br><span class="line">java <span class="string">'-Dfile.encoding=UTF-8'</span> hong.Person</span><br></pre></td></tr></tbody></table></figure><p></p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>Java 环境配置摘要</p>
<h2 id="下载安装jdk">下载安装JDK</h2>
<p><a target="_blank" rel="noopener" href="https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">官方下载链接</a>,下载对应版本后,双击安装即可</p>
<h2 id="配置环境变量">配置环境变量</h2>
<ol type="1">
<li>新建<code>JAVA_HOME</code>环境变量,变量值为jdk安装目录,我的电脑上为<code>C:\Program Files\Java\jdk1.8.0_144</code></li>
<li>新建 <code>CLASSPATH</code> 变量,变量值填写
<code>.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar</code></li>
<li><code>Path</code> 变量增加路径 <code>%JAVA_HOME%\bin</code> 和
<code>%JAVA_HOME%\jre\bin</code></li>
</ol>
<blockquote>
<p><strong>PS</strong>
以后安装其他版本jdk时只需修改<code>JAVA_HOME</code>环境变量即可</p>
</blockquote></body></html></summary>
<category term="java" scheme="http://ljmeng.site/categories/java/"/>
<category term="java" scheme="http://ljmeng.site/tags/java/"/>
</entry>
<entry>
<title>赛马问题</title>
<link href="http://ljmeng.site/posts/51644/"/>
<id>http://ljmeng.site/posts/51644/</id>
<published>2019-10-25T13:40:43.000Z</published>
<updated>2019-10-25T13:40:43.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p><strong>赛马问题</strong>:25匹马,5条赛道,每个跑道最多能有1匹马进行比赛,只能记录比较的名次信息,求最少赛多少次即可得出前五名?</p><p>先说结论:采用合适的策略,最坏比赛8次即可得到跑的最快的前五名。</p><p>虽然网上有很多分析,但是大多都是最坏要比较9次或10次的方案,并不够完善,我这里提供一个比较完整的分析。</p><span id="more"></span><h2 id="step-1">Step 1</h2><p>分成五组进行比赛,不妨设分别为A,B,C,D,E 五组。</p><p>每个马匹编号为$ A_i,i {1,2,3,4,5}$, <span class="math inline">\(A_i\)</span> 代表这匹马在A组中名次为 <span class="math inline">\(i\)</span> .</p><p>比赛结果如下 :(箭头指示快慢顺序)</p><figure><img src="/posts/51644/1572011965311.png" alt="1572011965311"><figcaption aria-hidden="true">1572011965311</figcaption></figure><h2 id="step-2">Step 2</h2><p>这一步比较关键,网上流传的答案大多是把<strong>所有跑第一的马</strong>(即A1,B1,C1,D1,E1)拉出来比较.而实际上把所<strong>所有跑第二的马</strong>拉出来比较是更好的选择。选第二名进行比较的好处在于可以排除14匹马,而选第一名只能排除10匹马。</p><p><strong>如果比较跑第一的马,那么得到的结果是这样的</strong>:</p><figure><img src="/posts/51644/1572014395248.png" alt="1572014395248"><figcaption aria-hidden="true">1572014395248</figcaption></figure><p>虚线包围的黄色区域是被排除的不可能进前五的马</p><p>红线圈出的马A1则是唯一确定进前五并且为所有马中跑的最快的马。</p><p><strong>如果比较跑第二的马,得到的结果如下</strong>:</p><figure><img src="/posts/51644/1572014706022.png" alt="1572014706022"><figcaption aria-hidden="true">1572014706022</figcaption></figure><p><strong>明显排除了更多的马</strong></p><h2 id="step-3">Step 3</h2><p>完成第一步和第二步后,我们已经比较了<strong>6次</strong>,只需要在不确定的10匹马中找出前四即可完成任务。</p><p>而这一步比较的方案是一个估计出的结果,在这一步中将 <strong>A3, B2,C1, D1, E1</strong> 拉出来进行比较即可。</p><p>我们着重以<strong>B2</strong>和<strong>A3</strong>的名次进行分情况讨论:</p><p>好吧,这里讨论挺复杂的。。。但是只要分析一下就可以得出(<strong>最多再额外比较两次即可选出前五</strong>)的结论。</p><h2 id="结论">结论</h2><p>重点在于第二步中,选取合适的马比较以排除最多数量的马(类似二分搜索的思想)</p></body></html>]]></content>
<summary type="html"><html><head></head><body><p><strong>赛马问题</strong>:25匹马,5条赛道,每个跑道最多能有1匹马进行比赛,只能记录比较的名次信息,求最少赛多少次即可得出前五名?</p>
<p>先说结论:采用合适的策略,最坏比赛8次即可得到跑的最快的前五名。</p>
<p>虽然网上有很多分析,但是大多都是最坏要比较9次或10次的方案,并不够完善,我这里提供一个比较完整的分析。</p></body></html></summary>
<category term="algorithm" scheme="http://ljmeng.site/categories/algorithm/"/>
<category term="algorithm" scheme="http://ljmeng.site/tags/algorithm/"/>
</entry>
<entry>
<title>CPP优雅的生成全排列</title>
<link href="http://ljmeng.site/posts/13886/"/>
<id>http://ljmeng.site/posts/13886/</id>
<published>2019-09-28T12:02:05.000Z</published>
<updated>2019-09-28T12:02:05.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p><strong>为何会有这个问题?</strong></p><p>网易笔试很悲催的遇到这个问题,然后脑子生锈用很蠢的循环去写,而且还没写出来,这里我整理了一些其他的办法来优化,争取做到高效,简洁,优美。</p><span id="more"></span><h3 id="方法一-stl的next_permutation">方法一:STL的next_permutation</h3><p>使用简洁,优美,但是不够高效,生成全部排列的复杂度大概为 $ O(n!*n)$,每次生成的复杂度为O(n). <a target="_blank" rel="noopener" href="https://zh.cppreference.com/w/cpp/algorithm/next_permutation">next_permutation</a></p><p>注意,生成前需要排序,按照$ < <span class="math inline">\(的顺序排序。或者自定义comp对象。\)</span> (fisrt,last, comp) $</p><figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><algorithm></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><vector></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">cout_nums</span><span class="params">(<span class="type">const</span> vector<<span class="type">int</span>> &nums)</span></span>{ <span class="comment">//打印数组</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<nums.<span class="built_in">size</span>();i++)</span><br><span class="line"> cout <<nums[i]<<<span class="string">" "</span>;</span><br><span class="line"> cout <<endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> vector<<span class="type">int</span>> nums; <span class="comment">//数组</span></span><br><span class="line"> vector<vector<<span class="type">int</span>>> permutations;<span class="comment">//存储所有排列</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<<span class="number">5</span>;i++) <span class="comment">//初始化数组</span></span><br><span class="line"> nums.<span class="built_in">push_back</span>(i);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">sort</span>(nums.<span class="built_in">begin</span>(),nums.<span class="built_in">end</span>()); <span class="comment">//按照从小到大的顺序排序</span></span><br><span class="line"> permutations.<span class="built_in">push_back</span>(<span class="built_in">vector</span><<span class="type">int</span>>(nums.<span class="built_in">begin</span>(),nums.<span class="built_in">end</span>())); </span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">next_permutation</span>(nums.<span class="built_in">begin</span>(),nums.<span class="built_in">end</span>()))<span class="comment">//生成下一个排列</span></span><br><span class="line"> permutations.<span class="built_in">push_back</span>(<span class="built_in">vector</span><<span class="type">int</span>>(nums.<span class="built_in">begin</span>(), nums.<span class="built_in">end</span>()));</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<permutations.<span class="built_in">size</span>();i++) <span class="comment">//打印所有排列</span></span><br><span class="line"> <span class="built_in">cout_nums</span>(permutations[i]);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="方法二-dfs-递归生成">方法二 DFS 递归生成</h3><p>速度理论最优<span class="math inline">\(O(n!)\)</span>,但实际和方法一速度差不多,都很慢。使用更简洁,不过实现时需要注意trick。</p><p>DFS就是模仿挑选的过程,值得注意的是这里采用<strong>交换来实现的挑选</strong>。</p><p>而为了保证生成不会重复,需要在<strong>额外进行一次交换来进行复位</strong>。</p><p>证明如下: <strong>交换,递归调用,再交换序列会恢复原状。</strong></p><p>对于长度为1的情况: 只有一次循环,且只和本身交换一次,显然成立</p><p> c == 第一次交换 ==> c => 递归调用(生成结果) == 第二次交换==> c 显然符合</p><p>假设长度为n是会恢复原状,则长度n+1时</p><p> <span class="math inline">\(x, (n_1,..,n_n)\)</span> ==第一次交换(与元素<span class="math inline">\(n_k\)</span>交换) ==><span class="math inline">\(n_x,(n_1,n_2,...,n_{k-1},x,n_{k+1},...,n_n)\)</span></p><p>==> 递归调用,长度为n的情况,结束后序列显然不变 ==第二次交换(将元素<span class="math inline">\(n_k\)</span> 放回) ==>得到原序列 <span class="math inline">\(x, (n_1,..,n_n)\)</span></p><p><strong>数列每次打乱都会恢复原状,因此每一次挑选都不会重复</strong>,不过结果是无序的</p><figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">perm</span><span class="params">(<span class="type">int</span> depth, vector<<span class="type">int</span>> &nums, vector<vector<<span class="type">int</span>>> &perms)</span></span>{</span><br><span class="line"> <span class="keyword">if</span> (depth >= nums.<span class="built_in">size</span>()){</span><br><span class="line"> perms.<span class="built_in">push_back</span>(<span class="built_in">vector</span><<span class="type">int</span>>(nums.<span class="built_in">begin</span>(), nums.<span class="built_in">end</span>()));</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = depth; i < nums.<span class="built_in">size</span>(); i++){</span><br><span class="line"> <span class="comment">//注意这里是两次交换,第一次交换挑选,第二次交换复位</span></span><br><span class="line"> <span class="built_in">swap</span>(nums[depth], nums[i]);</span><br><span class="line"> <span class="built_in">perm</span>(depth + <span class="number">1</span>, nums, perms);</span><br><span class="line"> <span class="built_in">swap</span>(nums[depth], nums[i]);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">perm</span><span class="params">(vector<<span class="type">int</span>> &nums, vector<vector<<span class="type">int</span>>> &perms)</span></span>{</span><br><span class="line"> <span class="comment">//对nums内的数字生成全排列</span></span><br><span class="line"> <span class="built_in">perm</span>(<span class="number">0</span>, nums, perms);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h4 id="使用方法如下">使用方法如下:</h4><figure class="highlight cpp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><algorithm></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><vector></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">cout_nums</span><span class="params">(<span class="type">const</span> vector<<span class="type">int</span>> &nums)</span></span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<nums.<span class="built_in">size</span>();i++)</span><br><span class="line"> cout <<nums[i]<<<span class="string">" "</span>;</span><br><span class="line"> cout <<endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">perm</span><span class="params">(<span class="type">int</span> depth, vector<<span class="type">int</span>> &nums, vector<vector<<span class="type">int</span>>> &perms)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span> (depth >= nums.<span class="built_in">size</span>())</span><br><span class="line"> {</span><br><span class="line"> perms.<span class="built_in">push_back</span>(<span class="built_in">vector</span><<span class="type">int</span>>(nums.<span class="built_in">begin</span>(), nums.<span class="built_in">end</span>()));</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = depth; i < nums.<span class="built_in">size</span>(); i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">swap</span>(nums[depth], nums[i]);</span><br><span class="line"> <span class="built_in">perm</span>(depth + <span class="number">1</span>, nums, perms);</span><br><span class="line"> <span class="built_in">swap</span>(nums[depth], nums[i]);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">perm</span><span class="params">(vector<<span class="type">int</span>> &nums, vector<vector<<span class="type">int</span>>> &perms)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="built_in">perm</span>(<span class="number">0</span>, nums, perms);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"></span><br><span class="line"> vector<<span class="type">int</span>> nums;</span><br><span class="line"> vector<vector<<span class="type">int</span>>> permutations;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<<span class="number">4</span>;i++)</span><br><span class="line"> nums.<span class="built_in">push_back</span>(i);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">perm</span>(nums,permutations);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<permutations.<span class="built_in">size</span>();i++)</span><br><span class="line"> <span class="built_in">cout_nums</span>(permutations[i]);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="结语">结语</h3><p>内置next_permutation或着采用 递归(DFS)+两次交换 实现。</p></body></html>]]></content>
<summary type="html"><html><head></head><body><p><strong>为何会有这个问题?</strong></p>
<p>网易笔试很悲催的遇到这个问题,然后脑子生锈用很蠢的循环去写,而且还没写出来,这里我整理了一些其他的办法来优化,争取做到
高效,简洁,优美。</p></body></html></summary>
<category term="c++" scheme="http://ljmeng.site/categories/c/"/>
<category term="algorithm" scheme="http://ljmeng.site/categories/c/algorithm/"/>
<category term="c++" scheme="http://ljmeng.site/tags/c/"/>
</entry>
<entry>
<title>小说人名提取</title>
<link href="http://ljmeng.site/posts/16539/"/>
<id>http://ljmeng.site/posts/16539/</id>
<published>2019-07-06T13:45:49.000Z</published>
<updated>2019-07-06T13:45:49.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>一个基于hanlp的小说人名关系提取工具</p><figure><img src="/posts/16539/santi.png" alt="santi"><figcaption aria-hidden="true">santi</figcaption></figure><span id="more"></span><p><strong><a target="_blank" rel="noopener" href="https://github.com/lingjiameng/NER4Novel">项目地址</a></strong></p><h2 id="特点">特点</h2><ul><li>直接使用hanlp训练好的模型,无专门自定义人名字典</li><li>自动人名统计</li><li>部分人名简称转换</li></ul><h2 id="使用方法">使用方法</h2><ol type="1"><li><p>将书以txt后缀保存在<code>book</code>目录下,并且以 utf-8格式保存</p></li><li><p>运行如下命令</p></li></ol><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python rel.py --book book_name <span class="comment">#注意没有txt后缀</span></span><br></pre></td></tr></tbody></table></figure><h2 id="运行结果展示">运行结果展示</h2><h3 id="平凡的世界">平凡的世界</h3><figure><img src="/posts/16539/pfdsj.png" alt="平凡的世界"><figcaption aria-hidden="true">平凡的世界</figcaption></figure><figure><img src="/posts/16539/pfdsj2.png" alt="pfdsj2"><figcaption aria-hidden="true">pfdsj2</figcaption></figure><figure><img src="/posts/16539/pfdsj3.png" alt="pfdsj3"><figcaption aria-hidden="true">pfdsj3</figcaption></figure><h3 id="三体">三体</h3><figure><img src="/posts/16539/santi.png" alt="santi"><figcaption aria-hidden="true">santi</figcaption></figure><figure><img src="/posts/16539/santi2.png" alt="santi2"><figcaption aria-hidden="true">santi2</figcaption></figure><figure><img src="/posts/16539/santi3.png" alt="santi3"><figcaption aria-hidden="true">santi3</figcaption></figure><h2 id="分词模型对比">分词模型对比</h2><ul><li>thulac 清华,大模型下载困难,小模型词性标注效果较差</li><li>jieba 词性标注不好,很容易误分类</li><li>hanlp 功能完整的工具包,分词效果不错</li><li>pynlpir 中科院,标注太奇怪,弃用</li><li>pyltp 哈工大</li></ul></body></html>]]></content>
<summary type="html"><html><head></head><body><p>一个基于hanlp的小说人名关系提取工具</p>
<figure>
<img src="/posts/16539/santi.png" alt="santi">
<figcaption aria-hidden="true">santi</figcaption>
</figure></body></html></summary>
<category term="NER" scheme="http://ljmeng.site/categories/NER/"/>
<category term="python" scheme="http://ljmeng.site/tags/python/"/>
<category term="NER" scheme="http://ljmeng.site/tags/NER/"/>
</entry>
<entry>
<title>记一次Opencv安装Error解决之旅</title>
<link href="http://ljmeng.site/posts/58371/"/>
<id>http://ljmeng.site/posts/58371/</id>
<published>2019-06-11T08:20:01.000Z</published>
<updated>2019-06-11T08:20:01.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>遇到<code>OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script)</code>的解决办法</p><span id="more"></span><h2 id="按提示修复">按提示修复</h2><p>根据提示,这种情况应该是缺少依赖,安装 <code>libgtk2.0-dev</code> 和<code>pkg-config</code>之后重新安装即可(源码安装的卸载后重新编译安装,第三方安装直接卸载后在重装)</p><p>在我的系统 <code>Ubuntu18.04</code> 下,命令如下:</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install libgtk2.0-dev pkg-config</span><br></pre></td></tr></tbody></table></figure><h2 id="提示不生效">提示不生效</h2><p>但是按照提示修复后仍然不生效,在我用的sdk编译后仍然会报相同的错误。</p><p>怎么办呢?,这时候我突然发现报错的路径很奇特</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">opt/conda/conda-bld/opencv-suite_1530789967746/work/modules/highgui/src/windows.cpp</span><br></pre></td></tr></tbody></table></figure><p>这个路径居然是 <code>conda</code>的,而我明明是使用源码编译安装的。</p><p>这时候我猛然反应过来,之前曾经使用<code>conda install opencv</code>安装过OpenCV,并且当时也报的是这个错。因为当时并没有修好这个错误,而是使用的<code>conda install opencv-python</code>解决的。因此这是一个环境变量的问题,<strong>系统没有识别我现在安装的包,而是识别了我之前安装错误的包</strong></p><h2 id="最终解决办法">最终解决办法</h2><p>1.查找系统中是否有 <code>OpenCV</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apt list | grep opencv</span><br></pre></td></tr></tbody></table></figure><p>2.在<code>conda</code>和<code>python</code>中查找是否有<code>OpenCV</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">conda list | grep opencv</span><br><span class="line">pip list | grep opencv</span><br></pre></td></tr></tbody></table></figure><p>3.将查找到的名为<code>libopencv</code>,<code>py-opencv</code>的包删除重装</p><p>卸载命令如下</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">conda remove libopencv</span><br><span class="line">conda remove py-opencv</span><br></pre></td></tr></tbody></table></figure><p>4.重新安装<code>OpenCV</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install libopencv</span><br></pre></td></tr></tbody></table></figure></body></html>]]></content>
<summary type="html"><html><head></head><body><p>遇到
<code>OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script)</code>
的解决办法</p></body></html></summary>
<category term="opencv" scheme="http://ljmeng.site/categories/opencv/"/>
<category term="ubuntu" scheme="http://ljmeng.site/tags/ubuntu/"/>
<category term="opencv" scheme="http://ljmeng.site/tags/opencv/"/>
</entry>
<entry>
<title>LaTeX笔记</title>
<link href="http://ljmeng.site/posts/58559/"/>
<id>http://ljmeng.site/posts/58559/</id>
<published>2019-05-28T12:06:09.000Z</published>
<updated>2019-05-28T12:06:09.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><h2 id="插入图片">插入图片</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{figure}[H] <span class="comment">%H为当前位置,!htb为忽略美学标准,htbp为浮动图形</span></span><br><span class="line"> <span class="keyword">\centering</span> <span class="comment">%图片居中</span></span><br><span class="line"> <span class="keyword">\includegraphics</span>[width=0.7<span class="keyword">\textwidth</span>,height=0.7<span class="keyword">\textheight</span>]{图片路径} <span class="comment">%插入图片,[]中设置图片大小,{}中是图片文件名</span></span><br><span class="line"> <span class="comment">% \caption{Main name 2} %最终文档中希望显示的图片标题</span></span><br><span class="line"> <span class="keyword">\label</span>{remix} <span class="comment">%用于文内引用的标签</span></span><br><span class="line"><span class="keyword">\end</span>{figure}</span><br></pre></td></tr></tbody></table></figure><span id="more"></span><h3 id="插入多张图片">插入多张图片</h3><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\usepackage</span>{graphicx}</span><br><span class="line"><span class="keyword">\usepackage</span>{subfigure}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">%这里的示例效果是并排显示两张图片后</span></span><br><span class="line"><span class="comment">%再换行后并排显示另外两张图片</span></span><br><span class="line"><span class="keyword">\begin</span>{figure}[htbp]</span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\subfigure</span>[pic1.]{</span><br><span class="line"><span class="keyword">\begin</span>{minipage}[t]{0.25<span class="keyword">\linewidth</span>}</span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\includegraphics</span>[width=1in]{111.eps}</span><br><span class="line"><span class="comment">%\caption{fig1}</span></span><br><span class="line"><span class="keyword">\end</span>{minipage}<span class="comment">%</span></span><br><span class="line">}<span class="comment">%</span></span><br><span class="line"><span class="keyword">\subfigure</span>[pic2.]{</span><br><span class="line"><span class="keyword">\begin</span>{minipage}[t]{0.25<span class="keyword">\linewidth</span>}</span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\includegraphics</span>[width=1in]{111.eps}</span><br><span class="line"><span class="comment">%\caption{fig2}</span></span><br><span class="line"><span class="keyword">\end</span>{minipage}<span class="comment">%</span></span><br><span class="line">}<span class="comment">%</span></span><br><span class="line"> <span class="comment">%这个回车键很重要(换行效果) \quad也可以</span></span><br><span class="line"><span class="keyword">\subfigure</span>[pic3.]{</span><br><span class="line"><span class="keyword">\begin</span>{minipage}[t]{0.25<span class="keyword">\linewidth</span>}</span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\includegraphics</span>[width=1in]{111.eps}</span><br><span class="line"><span class="comment">%\caption{fig2}</span></span><br><span class="line"><span class="keyword">\end</span>{minipage}</span><br><span class="line">}<span class="comment">%</span></span><br><span class="line"><span class="keyword">\subfigure</span>[pic4.]{</span><br><span class="line"><span class="keyword">\begin</span>{minipage}[t]{0.25<span class="keyword">\linewidth</span>}</span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\includegraphics</span>[width=1in]{111.eps}</span><br><span class="line"><span class="comment">%\caption{fig2}</span></span><br><span class="line"><span class="keyword">\end</span>{minipage}</span><br><span class="line">}<span class="comment">%</span></span><br><span class="line"><span class="keyword">\centering</span></span><br><span class="line"><span class="keyword">\caption</span>{ pics}</span><br><span class="line"><span class="keyword">\end</span>{figure}</span><br></pre></td></tr></tbody></table></figure><h2 id="列表缩进">列表缩进</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">% 添加在\begin{document}前</span></span><br><span class="line"><span class="keyword">\usepackage</span>{enumitem} </span><br><span class="line"></span><br><span class="line"><span class="keyword">\begin</span>{enumerate}[itemindent=1em] <span class="comment">%在这里设置缩进的距离</span></span><br><span class="line"><span class="keyword">\item</span> item0</span><br><span class="line"><span class="keyword">\item</span> item1</span><br><span class="line"><span class="keyword">\item</span> item2</span><br><span class="line"><span class="keyword">\end</span>{enumerate}</span><br></pre></td></tr></tbody></table></figure><h2 id="插入代码">插入代码</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\usepackage</span>{listings} <span class="comment">% 插入代码</span></span><br><span class="line"><span class="keyword">\lstset</span>{ <span class="comment">%代码格式自定义</span></span><br><span class="line"> columns=fixed, </span><br><span class="line"> numbers=left, <span class="comment">% 在左侧显示行号</span></span><br><span class="line"> numberstyle=<span class="keyword">\tiny</span><span class="keyword">\color</span>{gray}, <span class="comment">% 设定行号格式</span></span><br><span class="line"> frame=none, <span class="comment">% 不显示背景边框</span></span><br><span class="line"> keywordstyle=<span class="keyword">\color</span>[RGB]{40,40,255}, <span class="comment">% 设定关键字颜色</span></span><br><span class="line"> numberstyle=<span class="keyword">\footnotesize</span><span class="keyword">\color</span>{darkgray}, </span><br><span class="line"> commentstyle=<span class="keyword">\it</span><span class="keyword">\color</span>[RGB]{0,96,96}, <span class="comment">% 设置代码注释的格式</span></span><br><span class="line"> stringstyle=<span class="keyword">\rmfamily</span><span class="keyword">\slshape</span><span class="keyword">\color</span>[RGB]{128,0,0}, <span class="comment">% 设置字符串格式</span></span><br><span class="line"> showstringspaces=false, <span class="comment">% 不显示字符串中的空格</span></span><br><span class="line"> language=java, <span class="comment">% 设置语言</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">%正文使用</span></span><br><span class="line"><span class="keyword">\begin</span>{lstlisting} <span class="comment">% [breaklines]打开折行</span></span><br><span class="line">代码</span><br><span class="line"><span class="keyword">\end</span>{lstlisting}</span><br></pre></td></tr></tbody></table></figure><h2 id="设置目录显示级数">设置目录显示级数</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%通过调整数字即可控制显示级数,2为显示到subsection</span></span><br><span class="line"><span class="keyword">\setcounter</span>{tocdepth}{2}</span><br><span class="line"><span class="keyword">\tableofcontents</span></span><br></pre></td></tr></tbody></table></figure><h2 id="局部字体放大">局部字体放大</h2><p>从小到大排列</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\tiny</span></span><br><span class="line"><span class="keyword">\scriptsize</span></span><br><span class="line"><span class="keyword">\footnotesize</span></span><br><span class="line"><span class="keyword">\small</span></span><br><span class="line"><span class="keyword">\normalsize</span></span><br><span class="line"><span class="keyword">\large</span></span><br><span class="line"><span class="keyword">\Large</span></span><br><span class="line"><span class="keyword">\LARGE</span></span><br><span class="line"><span class="keyword">\huge</span></span><br><span class="line"><span class="keyword">\Huge</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%两种用法</span></span><br><span class="line"><span class="comment">%inline</span></span><br><span class="line">{<span class="keyword">\large</span> this is large<span class="keyword">\par</span>}</span><br><span class="line"><span class="comment">%environment</span></span><br><span class="line"><span class="keyword">\begin</span>{large}</span><br><span class="line">bla bla bla ...</span><br><span class="line"><span class="keyword">\end</span>{large}</span><br></pre></td></tr></tbody></table></figure><h2 id="页面居中">页面居中</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">% 垂直居中</span></span><br><span class="line"><span class="keyword">\vfill</span></span><br><span class="line">正文</span><br><span class="line"><span class="keyword">\vfill</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%垂直水平居中</span></span><br><span class="line"><span class="keyword">\vfill</span></span><br><span class="line"><span class="keyword">\center</span>{正文}</span><br><span class="line"><span class="keyword">\vfill</span></span><br></pre></td></tr></tbody></table></figure><h2 id="中文支持">中文支持</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%方法一:全文档中文支持</span></span><br><span class="line"><span class="comment">%文档开始添加如下行</span></span><br><span class="line"><span class="keyword">\usepackage</span>{ctex} </span><br><span class="line"></span><br><span class="line"><span class="comment">%方法二:局部文档中文支持</span></span><br><span class="line"><span class="comment">%文档开始添加</span></span><br><span class="line"><span class="keyword">\usepackage</span>{CJKutf8}</span><br><span class="line"></span><br><span class="line"><span class="comment">%正文使用中文时</span></span><br><span class="line"><span class="comment">%先添加begin</span></span><br><span class="line"><span class="keyword">\begin</span>{CJK}{UTF8}{gbsn}</span><br><span class="line">正文部分</span><br><span class="line"><span class="comment">%再添加end</span></span><br><span class="line"><span class="keyword">\end</span>{CJK}</span><br></pre></td></tr></tbody></table></figure><h2 id="默认打开全屏">默认打开全屏</h2><p>文档开头加入</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%pdf 打开默认全屏模式</span></span><br><span class="line"><span class="keyword">\hypersetup</span>{pdfpagemode=FullScreen}</span><br></pre></td></tr></tbody></table></figure><h2 id="数学公式">数学公式</h2><p>除了<code>$...$</code>和<code>$$...$$</code>之外</p><p>还有标准单个公式</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{equation}</span><br><span class="line"><span class="comment">%公式写在这里</span></span><br><span class="line"><span class="keyword">\end</span>{equation}</span><br></pre></td></tr></tbody></table></figure><h3 id="插入中文">插入中文</h3><p><code>\mbox{拒绝}</code>或者<code>\text{拒绝}</code></p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">$</span><span class="built_in">$</span> P<span class="keyword">\{</span><span class="keyword">\mbox</span>{拒绝} <span class="keyword">\mid</span> H<span class="built_in">_</span>{0} <span class="keyword">\mbox</span>{为真}<span class="keyword">\}</span> = <span class="keyword">\alpha</span> <span class="built_in">$</span><span class="built_in">$</span></span><br><span class="line"><span class="comment">%或者</span></span><br><span class="line"><span class="built_in">$</span><span class="built_in">$</span> P<span class="keyword">\{</span><span class="keyword">\text</span>{拒绝} <span class="keyword">\mid</span> H<span class="built_in">_</span>{0} <span class="keyword">\text</span>{为真}<span class="keyword">\}</span> = <span class="keyword">\alpha</span> <span class="built_in">$</span><span class="built_in">$</span></span><br></pre></td></tr></tbody></table></figure><p><span class="math display">\[ P\{\mbox{拒绝} \mid H_{0} \mbox{为真}\}= \alpha \]</span></p><h3 id="公式对齐">公式对齐</h3><h4 id="单独的公式环境">单独的公式环境</h4><p><strong>align</strong> 每行是一个公式,都会独立编号</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{align}</span><br><span class="line">f(x) <span class="built_in">&</span>= (x+a)(x+b) <span class="keyword">\\</span></span><br><span class="line"> <span class="built_in">&</span>= x<span class="built_in">^</span>2 + (a+b)x + ab</span><br><span class="line"><span class="keyword">\end</span>{align}</span><br></pre></td></tr></tbody></table></figure><p><strong>alignat</strong> 接收一个参数用来指定根据哪一列对齐</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{alignat}{2}</span><br><span class="line"> <span class="keyword">\sigma</span><span class="built_in">_</span>1 <span class="built_in">&</span>= x + y <span class="built_in">&</span><span class="keyword">\quad</span> <span class="keyword">\sigma</span><span class="built_in">_</span>2 <span class="built_in">&</span>= <span class="keyword">\frac</span>{x}{y} <span class="keyword">\\</span> </span><br><span class="line"> <span class="keyword">\sigma</span><span class="built_in">_</span>1' <span class="built_in">&</span>= <span class="keyword">\frac</span>{<span class="keyword">\partial</span> x + y}{<span class="keyword">\partial</span> x} <span class="built_in">&</span> <span class="keyword">\sigma</span><span class="built_in">_</span>2'</span><br><span class="line"> <span class="built_in">&</span>= <span class="keyword">\frac</span>{<span class="keyword">\partial</span> <span class="keyword">\frac</span>{x}{y}}{<span class="keyword">\partial</span> x}</span><br><span class="line"><span class="keyword">\end</span>{alignat}</span><br></pre></td></tr></tbody></table></figure><h4 id="内嵌的公式环境">内嵌的公式环境</h4><p>如果报错缺少包,可以用<code>\usepackage{amsmath}</code></p><p><strong>aligned</strong></p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{equation}</span><br><span class="line"> <span class="keyword">\left</span>.<span class="keyword">\begin</span>{aligned}</span><br><span class="line"> B'<span class="built_in">&</span>=-<span class="keyword">\partial</span> <span class="keyword">\times</span> E,<span class="keyword">\\</span></span><br><span class="line"> E'<span class="built_in">&</span>=<span class="keyword">\partial</span> <span class="keyword">\times</span> B - 4<span class="keyword">\pi</span> j,</span><br><span class="line"> <span class="keyword">\end</span>{aligned}</span><br><span class="line"> <span class="keyword">\right</span><span class="keyword">\}</span></span><br><span class="line"> <span class="keyword">\qquad</span> <span class="keyword">\text</span>{Maxwell's equations}</span><br><span class="line"><span class="keyword">\end</span>{equation}</span><br></pre></td></tr></tbody></table></figure><p><strong>split</strong>多个公式拆分成多行,但是它整体还只是一个公式。</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{equation}</span><br><span class="line"> <span class="keyword">\begin</span>{split}</span><br><span class="line"> (a + b)<span class="built_in">^</span>4</span><br><span class="line"> <span class="built_in">&</span>= (a + b)<span class="built_in">^</span>2 (a + b)<span class="built_in">^</span>2 <span class="keyword">\\</span></span><br><span class="line"> <span class="built_in">&</span>= (a<span class="built_in">^</span>2 + 2ab + b<span class="built_in">^</span>2)</span><br><span class="line"> (a<span class="built_in">^</span>2 + 2ab + b<span class="built_in">^</span>2) <span class="keyword">\\</span></span><br><span class="line"> <span class="built_in">&</span>= a<span class="built_in">^</span>4 + 4a<span class="built_in">^</span>3b + 6a<span class="built_in">^</span>2b<span class="built_in">^</span>2 + 4ab<span class="built_in">^</span>3 + b<span class="built_in">^</span>4</span><br><span class="line"> <span class="keyword">\end</span>{split}</span><br><span class="line"><span class="keyword">\end</span>{equation}</span><br></pre></td></tr></tbody></table></figure><h2 id="增加批注">增加批注</h2><p>可以在多人合作时使用</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\newcommand</span>{<span class="keyword">\meng</span>}[1]{<span class="keyword">\textcolor</span>{cyan}{[meng: <span class="params">#1</span>]}}</span><br><span class="line"></span><br><span class="line">ABC <span class="keyword">\meng</span>{revise this part later}</span><br></pre></td></tr></tbody></table></figure><h2 id="beamer">Beamer</h2><p>非常有用的维基beamer链接<a target="_blank" rel="noopener" href="https://en.wikibooks.org/wiki/LaTeX/Presentations">link</a></p><p>使用代码不正常时可以尝试加入<code>\begin{frame}[fragile]</code></p><h3 id="结构frame选项">结构(Frame)选项</h3><ul><li><code>\frame[plain]{\frametitle{}..}</code> 适用于如 本页 ( 第 10 页) 所用的 plane 结构!</li><li><code>[containsverbatim]</code> 适用于使用 verbatim 环境和<code>\verb</code>命令。</li><li><code>[allowframebreaks]</code>适用于一张幻灯片放不下内容时自动分开。</li><li><code>[shrink]</code> 适用于缩小内容充满一张幻灯片。</li><li><code>[squeeze]</code> 适用于挤压垂直空间。</li></ul><h3 id="增加页码">增加页码</h3><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%文档开头添加即可</span></span><br><span class="line"><span class="keyword">\addtobeamertemplate</span>{navigation symbols}{}{<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\usebeamerfont</span>{footline}<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\usebeamercolor</span>[fg]{footline}<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\hspace</span>{1em}<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertframenumber</span>/<span class="keyword">\inserttotalframenumber</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="增加目录">增加目录</h3><h4 id="开头目录">开头目录</h4><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{frame} <span class="comment">%生成目录页,目录太长时加选项[shrink]</span></span><br><span class="line"> <span class="keyword">\addtocounter</span>{framenumber}{-2} <span class="keyword">\frametitle</span>{目录}</span><br><span class="line"> <span class="keyword">\thispagestyle</span>{empty}</span><br><span class="line"> <span class="keyword">\tableofcontents</span> <span class="comment">% 也可以插入选项 [pausesections]</span></span><br><span class="line"> <span class="comment">%----------------------列目录时,隐藏所有的小节</span></span><br><span class="line"> <span class="comment">%\tableofcontents[hideallsubsections]</span></span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br></pre></td></tr></tbody></table></figure><h4 id="章节section目录">章节(section)目录</h4><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%注意 加在\document 后</span></span><br><span class="line"><span class="keyword">\AtBeginSection</span>[] <span class="comment">%该函数在每到一个subsection是就显示整篇文章的目录</span></span><br><span class="line">{</span><br><span class="line"><span class="keyword">\begin</span>{frame}<beamer>[plain]{目录} </span><br><span class="line"><span class="keyword">\tableofcontents</span>[currentsection, currentsubsection, hideothersubsections,]</span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="增加脚注引用">增加脚注引用</h3><p><code>biblatex</code>安装方法</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install texlive-bibtex-extra biber</span><br></pre></td></tr></tbody></table></figure><p>在\begin{document}前添加如下命令:</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\usepackage</span>[backend=bibtex,sorting=none]{biblatex}</span><br><span class="line"><span class="keyword">\addbibresource</span>{example.bib} <span class="comment">%BibTeX数据文件及位置</span></span><br><span class="line"><span class="keyword">\setbeamerfont</span>{footnote}{size=<span class="keyword">\tiny</span>}</span><br></pre></td></tr></tbody></table></figure><p>文中引用使用:</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\footfullcite</span>{bib<span class="built_in">_</span>item} <span class="comment">%脚注引用</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\cite</span>{bib<span class="built_in">_</span>item} <span class="comment">%正常引用</span></span><br></pre></td></tr></tbody></table></figure><h3 id="图文混排问题">图文混排问题</h3><p>一般用于左侧文字,右侧显示图片等</p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">%文档开头使用宏包</span></span><br><span class="line"><span class="keyword">\usepackage</span>{multicol}</span><br><span class="line"></span><br><span class="line"><span class="comment">%正文使用时</span></span><br><span class="line"><span class="keyword">\begin</span>{frame}{具有内热源的平板导热}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\begin</span>{columns}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\column</span>{0.65<span class="keyword">\textwidth</span>}<1-></span><br><span class="line">XXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span><br><span class="line">XXXXXXXXXXXX</span><br><span class="line"></span><br><span class="line"><span class="keyword">\column</span>{0.35<span class="keyword">\textwidth</span>}<1-></span><br><span class="line"></span><br><span class="line"><span class="keyword">\shadowbox</span>{</span><br><span class="line"><span class="keyword">\includegraphics</span>[width=0.9<span class="keyword">\textwidth</span>,totalheight=0.45<span class="keyword">\textheight</span>]{具有均匀内热源的平壁.png} </span><br><span class="line">} <span class="comment">%</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\end</span>{columns}</span><br><span class="line"></span><br><span class="line">~<span class="keyword">\\</span></span><br><span class="line">由此可见,与无内热源的平壁解相比,热流密度不再是常数,温度分布也不再是直线或抛物线,这些都是由于内热源引起的.</span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="我的beamer模板">我的beamer模板</h3><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\documentclass</span>[c,notes,uncompressed,mathserif,blue]{beamer} <span class="comment">%设定页面基本样式</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\usepackage</span>{listings} <span class="comment">% 插入代码</span></span><br><span class="line"><span class="keyword">\usepackage</span>{float} <span class="comment">% 图片美学</span></span><br><span class="line"><span class="keyword">\usepackage</span>[UTF8]{ctex} <span class="comment">%支持中文</span></span><br><span class="line"><span class="keyword">\usepackage</span>{multicol} <span class="comment">%单页分列显示</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">\lstset</span>{ <span class="comment">%代码格式自定义</span></span><br><span class="line"> columns=fixed, </span><br><span class="line"> numbers=left, <span class="comment">% 在左侧显示行号</span></span><br><span class="line"> numberstyle=<span class="keyword">\tiny</span><span class="keyword">\color</span>{gray}, <span class="comment">% 设定行号格式</span></span><br><span class="line"> frame=none, <span class="comment">% 不显示背景边框</span></span><br><span class="line"> keywordstyle=<span class="keyword">\color</span>[RGB]{40,40,255}, <span class="comment">% 设定关键字颜色</span></span><br><span class="line"> numberstyle=<span class="keyword">\footnotesize</span><span class="keyword">\color</span>{darkgray}, </span><br><span class="line"> commentstyle=<span class="keyword">\it</span><span class="keyword">\color</span>[RGB]{0,96,96}, <span class="comment">% 设置代码注释的格式</span></span><br><span class="line"> stringstyle=<span class="keyword">\rmfamily</span><span class="keyword">\slshape</span><span class="keyword">\color</span>[RGB]{128,0,0}, <span class="comment">% 设置字符串格式</span></span><br><span class="line"> showstringspaces=false, <span class="comment">% 不显示字符串中的空格</span></span><br><span class="line"> language=java, <span class="comment">% 设置语言</span></span><br><span class="line">}</span><br><span class="line"><span class="comment">% %---------------------------------</span></span><br><span class="line"><span class="comment">% % 取消注释,并将bib文件改名为reference.bib即可使用bib</span></span><br><span class="line"><span class="comment">% % 建议一并将结尾的参考文献页解注释</span></span><br><span class="line"><span class="comment">% % 使用biblatex进行文献引用,需要单独安装</span></span><br><span class="line"><span class="comment">% \usepackage[backend=bibtex,sorting=none]{biblatex}</span></span><br><span class="line"><span class="comment">% \addbibresource{reference.bib} %BibTeX数据文件及位置</span></span><br><span class="line"><span class="comment">% \setbeamerfont{footnote}{size=\tiny}</span></span><br><span class="line"></span><br><span class="line"><span class="comment">% %修改引用格式,使2引用显示正常</span></span><br><span class="line"><span class="comment">% \setbeamertemplate{bibliography item}[text]</span></span><br><span class="line"><span class="comment">% %-----------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%设置beamer主题和颜色主题</span></span><br><span class="line"><span class="keyword">\usetheme</span>{Antibes}</span><br><span class="line"><span class="comment">% \usetheme{Madrid} %此模板带页码</span></span><br><span class="line"><span class="comment">% \usecolortheme{lily} </span></span><br><span class="line"><span class="comment">% \usecolortheme{orchid} %此主题block背景有颜色</span></span><br><span class="line"><span class="comment">%------------针对Antibes的自定义配置-------------</span></span><br><span class="line"><span class="comment">%设置block为圆角并增加阴影</span></span><br><span class="line"><span class="keyword">\useinnertheme</span>[shadow=true]{rounded}</span><br><span class="line"></span><br><span class="line"><span class="comment">%------个人偏好,设置所有的序号为方形---</span></span><br><span class="line"><span class="comment">%参考 https://tex.stackexchange.com/questions/93874/where-can-i-find-a-list-of-itemize-bullet-shapes-in-latex-beamer</span></span><br><span class="line"><span class="comment">%设置有序和无序列表序号为方形</span></span><br><span class="line"><span class="keyword">\setbeamertemplate</span>{itemize items}[square]</span><br><span class="line"><span class="keyword">\setbeamertemplate</span>{enumerate items}[square]</span><br><span class="line"><span class="comment">% 参考 https://tex.stackexchange.com/questions/69720/latex-beamer-toc-dont-display-bubbles</span></span><br><span class="line"><span class="comment">%设置目录序号为方形</span></span><br><span class="line"><span class="keyword">\setbeamertemplate</span>{section in toc}[square]</span><br><span class="line"><span class="keyword">\setbeamertemplate</span>{subsection in toc}[square]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">% 设置标题颜色,去掉蓝色背景</span></span><br><span class="line"><span class="keyword">\definecolor</span>{dblue}{RGB}{00,33,99}</span><br><span class="line"><span class="keyword">\setbeamercolor</span>{frametitle}{fg=dblue,bg=}</span><br><span class="line"></span><br><span class="line"><span class="comment">% 重设下方导航条并增加页码</span></span><br><span class="line"><span class="keyword">\setbeamercolor</span>{footcolor}{fg=white,bg=structure!30}</span><br><span class="line"><span class="keyword">\setbeamertemplate</span>{navigation symbols}{}</span><br><span class="line"><span class="keyword">\addtobeamertemplate</span>{footline}{</span><br><span class="line"> <span class="keyword">\leavevmode</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\hbox</span>{<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\begin</span>{beamercolorbox}[wd=<span class="keyword">\paperwidth</span>,ht=2.75ex,dp=.5ex,right,rightskip=1em]{footcolor}<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\usebeamercolor</span>[fg]{navigation symbols}<span class="keyword">\insertslidenavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertframenavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertsubsectionnavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertsectionnavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertdocnavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\insertbackfindforwardnavigationsymbol</span><span class="comment">%</span></span><br><span class="line"> <span class="keyword">\hspace</span>{0.2em} <span class="comment">%适当隔开页码和导航符</span></span><br><span class="line"> <span class="keyword">\raisebox</span>{1.4pt}[0pt][0pt]{ <span class="comment">% 解决对齐问题</span></span><br><span class="line"> <span class="keyword">\textcolor</span>{red}{<span class="keyword">\insertframenumber</span>/<span class="keyword">\inserttotalframenumber</span>}<span class="comment">% 生成页码</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">\end</span>{beamercolorbox}<span class="comment">%</span></span><br><span class="line"> }<span class="comment">%</span></span><br><span class="line"> <span class="keyword">\vskip</span>0.5pt<span class="comment">%</span></span><br><span class="line">}{}</span><br><span class="line"></span><br><span class="line"><span class="comment">%pdf 打开默认全屏模式</span></span><br><span class="line"><span class="keyword">\hypersetup</span>{pdfpagemode=FullScreen}</span><br><span class="line"></span><br><span class="line"><span class="comment">%------------------------------------</span></span><br><span class="line"><span class="comment">%------------开始创作-----------------</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\title</span>{标题}</span><br><span class="line"><span class="keyword">\subtitle</span>{主题}</span><br><span class="line"><span class="keyword">\author</span>{作者}</span><br><span class="line"><span class="comment">%------------------------------------</span></span><br><span class="line"><span class="comment">%-------------------------------------</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">\begin</span>{document}</span><br><span class="line"><span class="comment">%------------------------------</span></span><br><span class="line"><span class="comment">%该函数在每到一个section前显示整篇文章的目录</span></span><br><span class="line"><span class="keyword">\AtBeginSection</span>[] </span><br><span class="line">{</span><br><span class="line"> <span class="keyword">\addtocounter</span>{framenumber}{-1} <span class="comment">%使此页不计入页码数</span></span><br><span class="line"> <span class="keyword">\begin</span>{frame}<beamer>[plain]{目录}</span><br><span class="line"> <span class="keyword">\tableofcontents</span>[currentsection,currentsubsection,hideothersubsections,]<span class="comment">%调整选项可以选择显示的内容</span></span><br><span class="line"> <span class="keyword">\end</span>{frame}</span><br><span class="line">}</span><br><span class="line"><span class="comment">%---------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%----------------------------------</span></span><br><span class="line"><span class="comment">% 标题页面</span></span><br><span class="line"><span class="keyword">\begin</span>{frame}[plain]</span><br><span class="line"><span class="keyword">\titlepage</span></span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line"></span><br><span class="line"><span class="comment">% 目录页面</span></span><br><span class="line"><span class="keyword">\begin</span>{frame}[plain] <span class="comment">%生成目录页,目录太长时加选项[shrink]</span></span><br><span class="line"> <span class="keyword">\addtocounter</span>{framenumber}{-2} </span><br><span class="line"> <span class="keyword">\frametitle</span>{目录}</span><br><span class="line"> <span class="comment">% \tableofcontents % 也可以插入选项 [pausesections]</span></span><br><span class="line"> <span class="keyword">\tableofcontents</span>[hideallsubsections] <span class="comment">%列目录时,隐藏所有的小节</span></span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line"><span class="comment">%--------------------------------------</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">%------------------------------------</span></span><br><span class="line"><span class="comment">%------------开始创作-----------------</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">% % -------- 选用功能 -------------</span></span><br><span class="line"><span class="comment">% % -------- 每个章节的名字单独显示,给人切换感</span></span><br><span class="line"><span class="comment">% \begin{frame}[plain]</span></span><br><span class="line"><span class="comment">% \addtocounter{framenumber}{-1}</span></span><br><span class="line"><span class="comment">% \vfill</span></span><br><span class="line"><span class="comment">% \center{\Huge{章节名}}</span></span><br><span class="line"><span class="comment">% \vfill</span></span><br><span class="line"><span class="comment">% \end{frame}</span></span><br><span class="line"></span><br><span class="line"><span class="comment">% --------------- 以下为示例 -----------</span></span><br><span class="line"><span class="keyword">\section</span>{第一章}</span><br><span class="line"><span class="keyword">\subsection</span>{第一节}</span><br><span class="line"><span class="keyword">\begin</span>{frame}{第一节}{子标题}</span><br><span class="line"> blablabla...</span><br><span class="line"> <span class="keyword">\begin</span>{exampleblock}{例子}</span><br><span class="line"> 这是一个exampleblock示例</span><br><span class="line"> <span class="keyword">\end</span>{exampleblock}</span><br><span class="line"> 这是一个item示例</span><br><span class="line"> <span class="keyword">\begin</span>{itemize}</span><br><span class="line"> <span class="keyword">\item</span> item1</span><br><span class="line"> <span class="keyword">\item</span> item2</span><br><span class="line"> <span class="keyword">\end</span>{itemize}</span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line"></span><br><span class="line"><span class="comment">% \subsection{第二节}</span></span><br><span class="line"><span class="comment">% \begin{frame}{第二节}{子标题}</span></span><br><span class="line"><span class="comment">% blablabla...</span></span><br><span class="line"><span class="comment">% 这是一个引用的例子\footfullcite{prashanthjoshiSurveySecurityPrivacy2018}</span></span><br><span class="line"><span class="comment">% \end{frame}</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">% ------------------------</span></span><br><span class="line"><span class="comment">% ----------结束页面--------</span></span><br><span class="line"><span class="comment">% % -----参考文献页面</span></span><br><span class="line"><span class="comment">% \begin{frame}{参考文献}</span></span><br><span class="line"><span class="comment">% \printbibliography</span></span><br><span class="line"><span class="comment">% \end{frame}</span></span><br><span class="line"></span><br><span class="line"><span class="comment">% -----致谢页面</span></span><br><span class="line"><span class="keyword">\begin</span>{frame}[plain]</span><br><span class="line"> <span class="keyword">\vfill</span></span><br><span class="line"> <span class="keyword">\center</span>{<span class="keyword">\Huge</span>{Thanks}}</span><br><span class="line"> <span class="keyword">\vfill</span></span><br><span class="line"><span class="keyword">\end</span>{frame}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\end</span>{document}</span><br></pre></td></tr></tbody></table></figure><h2 id="latex模板">Latex模板</h2><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\documentclass</span>{ctexart}</span><br><span class="line"><span class="comment">% \usepackage[utf8]{inputenc}</span></span><br><span class="line"><span class="comment">% \usepackage[fontset=ubuntu]{ctex}</span></span><br><span class="line"><span class="keyword">\usepackage</span>{amsmath}</span><br><span class="line"><span class="keyword">\usepackage</span>{xcolor}</span><br><span class="line"><span class="keyword">\usepackage</span>{color}</span><br><span class="line"><span class="keyword">\usepackage</span>{subfigure}</span><br><span class="line"><span class="keyword">\usepackage</span>{graphicx}</span><br><span class="line"><span class="keyword">\usepackage</span>{geometry}</span><br><span class="line"><span class="keyword">\usepackage</span>{hyperref}</span><br><span class="line"><span class="keyword">\usepackage</span>{authblk}</span><br><span class="line"><span class="keyword">\usepackage</span>{multirow}</span><br><span class="line"><span class="keyword">\usepackage</span>{url}</span><br><span class="line"><span class="keyword">\usepackage</span>{appendix}</span><br><span class="line"><span class="keyword">\usepackage</span>{dsfont}</span><br><span class="line"><span class="keyword">\usepackage</span>{amsfonts}</span><br><span class="line"><span class="keyword">\usepackage</span>{enumitem}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\newcommand</span>{<span class="keyword">\wang</span>}[1]{<span class="keyword">\textcolor</span>{cyan}{[wang: <span class="params">#1</span>]}}</span><br><span class="line"><span class="keyword">\newcommand</span>{<span class="keyword">\zhang</span>}[2]{<span class="keyword">\textcolor</span>{red}{[zhang: <span class="params">#1</span>]}}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\title</span>{标题<span class="keyword">\\</span>[2ex]<span class="keyword">\begin</span>{large}副标题<span class="keyword">\end</span>{large}}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\author</span>{Authors}</span><br><span class="line"><span class="keyword">\date</span>{}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\begin</span>{document}</span><br><span class="line"></span><br><span class="line"><span class="keyword">\maketitle</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\section</span>{示例}</span><br><span class="line"></span><br><span class="line">插入表格<span class="keyword">\ref</span>{tab:resnet}示例</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">\begin</span>{table}[htbp]</span><br><span class="line"><span class="keyword">\scalebox</span>{0.9}{</span><br><span class="line"><span class="keyword">\begin</span>{tabular}{|c|c|c|c|c|}</span><br><span class="line"><span class="keyword">\hline</span></span><br><span class="line">Error Rate <span class="built_in">&</span> Learning Rate 1.0 <span class="built_in">&</span> Learning Rate 0.1 <span class="built_in">&</span> Learning Rate 0.01 <span class="built_in">&</span> Learning Rate 0.0001 <span class="keyword">\\</span> <span class="keyword">\hline</span></span><br><span class="line">ResNet20 <span class="built_in">&</span> 9.64<span class="keyword">\%</span> <span class="built_in">&</span> 8.19<span class="keyword">\%</span> <span class="built_in">&</span> 10.88<span class="keyword">\%</span> <span class="built_in">&</span> 17.09<span class="keyword">\%</span> <span class="keyword">\\</span> <span class="keyword">\hline</span></span><br><span class="line">ResNet32 <span class="built_in">&</span> 8.51<span class="keyword">\%</span> <span class="built_in">&</span> 7.52<span class="keyword">\%</span> <span class="built_in">&</span> 10.22<span class="keyword">\%</span> <span class="built_in">&</span> 16.54<span class="keyword">\%</span> <span class="keyword">\\</span> <span class="keyword">\hline</span></span><br><span class="line">ResNet44 <span class="built_in">&</span> 11.00<span class="keyword">\%</span> <span class="built_in">&</span> 7.24<span class="keyword">\%</span> <span class="built_in">&</span> 10.01<span class="keyword">\%</span> <span class="built_in">&</span> 15.84<span class="keyword">\%</span> <span class="keyword">\\</span> <span class="keyword">\hline</span></span><br><span class="line">ResNet56 <span class="built_in">&</span> 8.54<span class="keyword">\%</span> <span class="built_in">&</span> 6.87<span class="keyword">\%</span> <span class="built_in">&</span> 9.36<span class="keyword">\%</span> <span class="built_in">&</span> 15.56<span class="keyword">\%</span> <span class="keyword">\\</span> <span class="keyword">\hline</span></span><br><span class="line"><span class="keyword">\end</span>{tabular}}</span><br><span class="line"><span class="keyword">\label</span>{tab:resnet}</span><br><span class="line"><span class="keyword">\caption</span>{Different Layer Number}</span><br><span class="line"><span class="keyword">\end</span>{table}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">\wang</span>{This is a tag}<span class="keyword">\cite</span>{Kingma2014AutoEncodingVB}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">% 引用</span></span><br><span class="line"><span class="keyword">\bibliographystyle</span>{plain}</span><br><span class="line"><span class="keyword">\bibliography</span>{bib.bib}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">% %附录</span></span><br><span class="line"><span class="comment">% \section*{附录}</span></span><br><span class="line"><span class="comment">% \appendix</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">\end</span>{document}</span><br></pre></td></tr></tbody></table></figure></body></html>]]></content>
<summary type="html"><html><head></head><body><h2 id="插入图片">插入图片</h2>
<figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">\begin</span>{figure}[H] <span class="comment">%H为当前位置,!htb为忽略美学标准,htbp为浮动图形</span></span><br><span class="line"> <span class="keyword">\centering</span> <span class="comment">%图片居中</span></span><br><span class="line"> <span class="keyword">\includegraphics</span>[width=0.7<span class="keyword">\textwidth</span>,height=0.7<span class="keyword">\textheight</span>]{图片路径} <span class="comment">%插入图片,[]中设置图片大小,{}中是图片文件名</span></span><br><span class="line"> <span class="comment">% \caption{Main name 2} %最终文档中希望显示的图片标题</span></span><br><span class="line"> <span class="keyword">\label</span>{remix} <span class="comment">%用于文内引用的标签</span></span><br><span class="line"><span class="keyword">\end</span>{figure}</span><br></pre></td></tr></tbody></table></figure></body></html></summary>
<category term="LaTeX" scheme="http://ljmeng.site/categories/LaTeX/"/>
<category term="LaTeX" scheme="http://ljmeng.site/tags/LaTeX/"/>
</entry>
<entry>
<title>Matlab学习笔记</title>
<link href="http://ljmeng.site/posts/29380/"/>
<id>http://ljmeng.site/posts/29380/</id>
<published>2019-03-29T08:28:32.000Z</published>
<updated>2019-03-29T08:28:32.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><h2 id="basics">Basics</h2><h3 id="define-sequence">Define sequence</h3><p>定义序列</p><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">a = <span class="number">2</span>:<span class="number">5</span>; <span class="comment">% meaning a=[2 3 4 5], size 1x4, row vector</span></span><br><span class="line">a = [<span class="number">2</span> <span class="number">3</span> <span class="number">4</span> <span class="number">5</span>]; <span class="comment">% same as above</span></span><br><span class="line">a = [<span class="number">2</span>; <span class="number">3</span>; <span class="number">4</span>; <span class="number">5</span>]; <span class="comment">% size 4x1, column vector</span></span><br><span class="line">a = <span class="number">2</span>:<span class="number">0.5</span>:<span class="number">5</span>; <span class="comment">% meaning a=[2 2.5 3 3.5 4 4.5 5], step 0.5</span></span><br></pre></td></tr></tbody></table></figure><span id="more"></span><h3 id="use-sequence-element">Use sequence element</h3><p>序列元素使用</p><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">c = a(<span class="number">3</span>); <span class="comment">% get value of a(3), not a[3], c is a number</span></span><br><span class="line">c = a(<span class="number">2</span>:<span class="number">4</span>); <span class="comment">% c = [a(2) a(3) a(4)], c is a row vector</span></span><br><span class="line">c = a’; <span class="comment">% c is the conjugate transpose (共轭转置) of a, c is column vector</span></span><br><span class="line">c = a.’; <span class="comment">% c is the transpose(转置) of a</span></span><br></pre></td></tr></tbody></table></figure><p>注意事项:</p><ul><li><code>sequence</code>元素编号从1开始</li><li>命令行末尾加<code>;</code> 则不显示结果,否则显示结果</li></ul><h3 id="operation">Operation</h3><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">a = <span class="number">2</span>:<span class="number">5</span>;</span><br><span class="line">b = <span class="number">9</span>:<span class="number">12</span>; <span class="comment">% a, b should be same size</span></span><br><span class="line">c = a+b;</span><br><span class="line">c = a-b;</span><br><span class="line">c = a.*b; <span class="comment">% meaning c(i)=a(i)*b(i), c=a*b is not valid</span></span><br><span class="line">c = a./b; <span class="comment">% meaning c(i)=a(i)/b(i), c=a/b is not valid</span></span><br><span class="line">c = a.^<span class="number">3</span>; <span class="comment">% meaning c(i)=a(i)^3, c=a^3 is not valid</span></span><br></pre></td></tr></tbody></table></figure><p><span id="inline-blue">注意事项:</span></p><ul><li><code>.*</code>,<code>./</code>,<code>.^</code>表示对向量中的元素做运算.这三个运算符均为二元运算符,即<code>2.^A</code>和<code>A.^2</code>是相同的</li><li>若不带<code>.</code>则表示对向量以矩阵的方式做运算,即矩阵相乘,矩阵相除和矩阵的幂</li></ul><h3 id="help">Help</h3><p>使用help指令可以查询命令的介绍信息</p><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">help stem</span><br><span class="line">help <span class="built_in">plot</span></span><br></pre></td></tr></tbody></table></figure><h3 id="functions">Functions</h3><p>常用函数</p><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">% X横坐标,Y纵坐标。X和Y的大小相同</span></span><br><span class="line">stem(X,Y) <span class="comment">% 散点图</span></span><br><span class="line"><span class="built_in">plot</span>(X,Y) <span class="comment">% 折线图</span></span><br><span class="line"></span><br><span class="line"><span class="comment">% B(微分方程X的系数),A(微分方程Y的系数)</span></span><br><span class="line"><span class="comment">% H(Z) = B / A ;</span></span><br><span class="line"><span class="comment">% x 系统的输入信号</span></span><br><span class="line">zplane(B,A) <span class="comment">% 零极点图</span></span><br><span class="line">filter(B,A,x) <span class="comment">% LTI系统,Return y(响应在时域上的分布)</span></span><br><span class="line"></span><br><span class="line">freqz(B,A,<span class="string">'whole'</span>) <span class="comment">% 'whole' 可改为n,代表了采样的数量</span></span><br><span class="line"><span class="comment">% 返回值【H,W】LTI系统函数H(z)在频域上的分布</span></span><br></pre></td></tr></tbody></table></figure><p>1.画图</p><figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">% 同时画多个图</span></span><br><span class="line"><span class="comment">% 方法一,使用figure,会在不同的窗口显示</span></span><br><span class="line"><span class="built_in">figure</span>(<span class="number">1</span>);</span><br><span class="line">stem(X,Y); <span class="comment">% or plot(X,Y)</span></span><br><span class="line">title(<span class="string">"figure 1"</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">figure</span>(<span class="number">2</span>);</span><br><span class="line">stem(X2,Y2); <span class="comment">% or plot(X,Y)</span></span><br><span class="line">title(<span class="string">"figure 2"</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">% 方法二,使用subplot,会在同一窗口显示</span></span><br><span class="line">subplot(<span class="number">2</span>,<span class="number">1</span>,<span class="number">1</span>)</span><br><span class="line"><span class="built_in">plot</span>(f,m)</span><br><span class="line">title(<span class="string">'Magnitude'</span>)</span><br><span class="line">ax = gca;</span><br><span class="line">ax.XTick = [<span class="number">15</span> <span class="number">40</span> <span class="number">60</span> <span class="number">85</span>];</span><br><span class="line"></span><br><span class="line">subplot(<span class="number">2</span>,<span class="number">1</span>,<span class="number">2</span>)</span><br><span class="line"><span class="built_in">plot</span>(f,p*<span class="number">180</span>/<span class="built_in">pi</span>)</span><br><span class="line">title(<span class="string">'Phase'</span>)</span><br><span class="line">ax = gca;</span><br><span class="line">ax.XTick = [<span class="number">15</span> <span class="number">40</span> <span class="number">60</span> <span class="number">85</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">%两者可以结合subplot是对figure的划分</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%同一窗口同一区域画多个图</span></span><br><span class="line"><span class="built_in">hold</span> on</span><br><span class="line"><span class="built_in">hold</span> off</span><br><span class="line"><span class="built_in">hold</span> all</span><br></pre></td></tr></tbody></table></figure></body></html>]]></content>
<summary type="html"><html><head></head><body><h2 id="basics">Basics</h2>
<h3 id="define-sequence">Define sequence</h3>
<p>定义序列</p>
<figure class="highlight matlab"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">a = <span class="number">2</span>:<span class="number">5</span>; <span class="comment">% meaning a=[2 3 4 5], size 1x4, row vector</span></span><br><span class="line">a = [<span class="number">2</span> <span class="number">3</span> <span class="number">4</span> <span class="number">5</span>]; <span class="comment">% same as above</span></span><br><span class="line">a = [<span class="number">2</span>; <span class="number">3</span>; <span class="number">4</span>; <span class="number">5</span>]; <span class="comment">% size 4x1, column vector</span></span><br><span class="line">a = <span class="number">2</span>:<span class="number">0.5</span>:<span class="number">5</span>; <span class="comment">% meaning a=[2 2.5 3 3.5 4 4.5 5], step 0.5</span></span><br></pre></td></tr></tbody></table></figure></body></html></summary>
<category term="Matlab" scheme="http://ljmeng.site/categories/Matlab/"/>
<category term="Matlab" scheme="http://ljmeng.site/tags/Matlab/"/>
</entry>
<entry>
<title>随手记</title>
<link href="http://ljmeng.site/posts/37449/"/>
<id>http://ljmeng.site/posts/37449/</id>
<published>2019-03-22T06:41:19.000Z</published>
<updated>2019-03-22T06:41:19.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><h2 id="随手记">随手记</h2><blockquote><p>樱花落下的速度是每秒五厘米, 我该用怎么样的速度,才能与你相遇。雨滴降落的速度是每秒十米,我该用怎么样的速度,才能将你挽留。陨石坠落的速度是每秒十千米,我该用怎么样的速度,才能将你拯救。烟花消散的速度是每秒三亿米,我该用什么样的速度,才能将你追回。——摘自网易云音乐《打上花火》评论</p></blockquote><span id="more"></span><blockquote><p>we are nothing but dust and shadows ― Horace, The Odes of Horace</p></blockquote><blockquote><p>我总嚷嚷着要找对象,可是从来没有主动想要去勾搭谁,我害怕快餐爱情,害怕分开,害怕最后我认真了别人却只是敷衍所以我等,等一个到最后还在我身边的人,我坚持或者偏执的相信有一个人会看穿我假装的冷漠,真正的靠近我留在我身边爱着我也给我一个机会去爱她如果最后能在一起,那么晚点也没关系。</p><p> (总结起来就俩字:矫情)——网易云《吟游诗人》</p></blockquote><blockquote><p>3米外六亲不认,10米外人畜不分,百米外天地融合</p></blockquote><blockquote><p>“有些事,非得问出来?不问就是压在他心头,压一辈子;一旦问出来了,这石头就是压在你心头了”——电影《心迷宫》</p></blockquote></body></html>]]></content>
<summary type="html"><html><head></head><body><h2 id="随手记">随手记</h2>
<blockquote>
<p>樱花落下的速度是每秒五厘米, 我该用怎么样的速度,才能与你相遇。
雨滴降落的速度是每秒十米,我该用怎么样的速度,才能将你挽留。
陨石坠落的速度是每秒十千米,我该用怎么样的速度,才能将你拯救。
烟花消散的速度是每秒三亿米,我该用什么样的速度,才能将你追回。
——摘自网易云音乐《打上花火》评论</p>
</blockquote></body></html></summary>
<category term="notes" scheme="http://ljmeng.site/categories/notes/"/>
<category term="notes" scheme="http://ljmeng.site/tags/notes/"/>
</entry>
<entry>
<title>python链式比较</title>
<link href="http://ljmeng.site/posts/14985/"/>
<id>http://ljmeng.site/posts/14985/</id>
<published>2019-03-18T16:22:21.000Z</published>
<updated>2019-03-18T16:22:21.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>Python中<code>print('a' < 'b' < 'c')</code>的运行结果是什么呢?</p><figure><img src="/posts/14985/1552928102571.png" alt="1552928102571"><figcaption aria-hidden="true">1552928102571</figcaption></figure><span id="more"></span><h2 id="part-1">Part 1</h2><p>本文来自一个奇怪的问题</p><p><code>print('a' < 'b' < 'c')</code>的运行结果是什么?</p><p><strong>答案是True</strong></p><p>这段代码在Python2 和Python3上的运行结果是相同的,均为True.</p><figure><img src="/posts/14985/1552928182146.png" alt="1552928182146"><figcaption aria-hidden="true">1552928182146</figcaption></figure><h2 id="part-2">Part 2</h2><p>但是这是为啥呢?</p><p>直觉猜测这是按照运算优先级进行的运算,即:</p><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="string">'a'</span> < <span class="string">'b'</span> < <span class="string">'c'</span>)</span><br><span class="line"><span class="comment"># 等同于</span></span><br><span class="line"><span class="built_in">print</span>((<span class="string">'a'</span> < <span class="string">'b'</span>) < <span class="string">'c'</span>)</span><br></pre></td></tr></tbody></table></figure><p>但这段代码在Python2和Python3中的运行结果是不同的:Python2运行结果仍为<code>True</code>.Python3中则运行出错,错误信息如下:</p><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">>>> </span><span class="built_in">print</span>((<span class="string">'a'</span><<span class="string">'b'</span>)<<span class="string">'c'</span>)</span><br><span class="line">Traceback (most recent call last):</span><br><span class="line"> File <span class="string">"<stdin>"</span>, line <span class="number">1</span>, <span class="keyword">in</span> <module></span><br><span class="line">TypeError: unorderable types: <span class="built_in">bool</span>() < <span class="built_in">str</span>()</span><br></pre></td></tr></tbody></table></figure><p>从这里我们可以看出两点:</p><ul><li>我们的猜测是错误的,并非是顺序结合执行的</li><li>Python3对比较的要求更加严格,不会进行自动类型转换(<span class="math inline">\(bool \to str\)</span>)</li></ul><p>实际测试确实如此,在逻辑比较运算中,数字和布尔值都不会自动转换为字符串来进行比较</p><h2 id="part3">Part3</h2><p>那问题来了,上述的思路不行,那实际到底发生了啥呢?</p><p>经过谷歌搜索,我终于在<a target="_blank" rel="noopener" href="https://docs.python.org/2.3/ref/comparisons.html">官方文档</a>中找到了相关说明:</p><blockquote><p>if a, b, c, ..., y, z are expressions and opa, opb, ..., opy arecomparison operators, then a opa b opb c ...y opy z is equivalent to aopa b <code>and</code> b opb c <code>and</code> ... y opy z, except thateach expression is evaluated at most once.</p></blockquote><p>这段话的意思就是</p><p>如果有一个比较如下 :</p><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'a'</span> < <span class="string">'b'</span> < <span class="string">'c'</span> < ...</span><br></pre></td></tr></tbody></table></figure><p>它相当于:</p><figure class="highlight python"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'a'</span> < <span class="string">'b'</span> <span class="keyword">and</span> <span class="string">'b'</span> < <span class="string">'c'</span> <span class="keyword">and</span> <span class="string">'c'</span> < ...</span><br></pre></td></tr></tbody></table></figure><h2 id="final">Final</h2><p>至此问题终于得到了解决</p><p><code>'a' < 'b' < 'c'</code> 被Python翻译为了<code>'a' < 'b' and 'b' < 'c'</code>.</p><p>所以结果理所当然的为<code>True</code>喽!</p></body></html>]]></content>
<summary type="html"><html><head></head><body><p>Python中<code>print('a' &lt; 'b' &lt; 'c')</code>的运行结果是什么呢?</p>
<figure>
<img src="/posts/14985/1552928102571.png" alt="1552928102571">
<figcaption aria-hidden="true">1552928102571</figcaption>
</figure></body></html></summary>
<category term="python" scheme="http://ljmeng.site/categories/python/"/>
<category term="python" scheme="http://ljmeng.site/tags/python/"/>
<category term="python 语法" scheme="http://ljmeng.site/tags/python-%E8%AF%AD%E6%B3%95/"/>
</entry>
<entry>
<title>快速搭建博客指南</title>
<link href="http://ljmeng.site/posts/19110/"/>
<id>http://ljmeng.site/posts/19110/</id>
<published>2019-03-17T16:22:21.000Z</published>
<updated>2019-03-17T16:22:21.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><h2 id="安装hexo">安装hexo</h2><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g hexo-cli</span><br><span class="line"></span><br><span class="line"><span class="comment"># Hexo 将会在指定文件夹中新建所需要的文件</span></span><br><span class="line">$ hexo init <folder></span><br><span class="line">$ <span class="built_in">cd</span> <folder></span><br><span class="line">$ npm install</span><br><span class="line"></span><br><span class="line"><span class="comment">#安装git</span></span><br><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></tbody></table></figure><h2 id="安装next主题">安装NexT主题</h2><p><a target="_blank" rel="noopener" href="https://github.com/theme-next/hexo-theme-next/blob/master/docs/INSTALLATION.md">参考链接</a></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">mkdir</span> themes/next</span><br><span class="line">$ curl -s https://api.github.com/repos/theme-next/hexo-theme-next/releases/latest | grep tarball_url | <span class="built_in">cut</span> -d <span class="string">'"'</span> -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1</span><br></pre></td></tr></tbody></table></figure><span id="more"></span><h2 id="配置博客和主题设置">配置博客和主题设置</h2><p>修改主题设置文件,并根据其中的说明<strong>做相应的安装工作</strong>这一步是最繁琐的,要有耐心,下面开始逐项说明: <strong>PS:为方便,只需要修改配置文件的改动省略</strong> <strong>gitclone全部都要到主题NexT根目录下运行</strong></p><h3 id="头像">头像</h3><p>1.头像放入<code>blog/themes/next/source/images</code>文件夹</p><h3 id="推荐">推荐</h3><p>2.安装推荐插件<code>npm install hexo-related-popular-posts --save</code></p><h3 id="标签云">标签云</h3><p>3.新建页面<code>tags</code>,<code>categories</code>,<code>about</code>,并增加相应<code>type</code>头格式</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo new page tags</span><br><span class="line">hexo new page categories</span><br><span class="line">hexo new page about</span><br></pre></td></tr></tbody></table></figure><h3 id="分享按钮">分享按钮</h3><p>4.分享按钮<code>git clone https://github.com/theme-next/theme-next-needmoreshare2 source/lib/needsharebutton</code></p><h3 id="本地搜索">本地搜索</h3><p>5.本地搜索安装<code>npm install hexo-generator-searchdb --save</code></p><h3 id="pdf支持">pdf支持</h3><p>6.支持pdf<code>git clone https://github.com/theme-next/theme-next-pdf source/lib/pdf</code></p><p>示例:</p><p>TOFIX: 手机上不能正常显示....</p><h3 id="fancybox">fancybox</h3><p>7.安装fancybox<code>git clone https://github.com/theme-next/theme-next-fancybox3 source/lib/fancybox</code></p><h3 id="显示图片">显示图片</h3><p>8.安装显示图片插件<code>npm install hexo-asset-image-fixed --save</code></p><h3 id="加载进度条">加载进度条</h3><p>9.安装加载进度条<code>git clone https://github.com/theme-next/theme-next-pace source/lib/pace</code></p><p>示例: <code>![发枪机器](搭建hexo博客/发枪机器.png)</code></p><h3 id="公式支持">公式支持</h3><p>1.安装配置<code>hexo-render-pandoc</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">npm un hexo-renderer-marked --save</span><br><span class="line"><span class="comment">#or npm un hexo-renderer-kramed --save (如果安装的是kramed的话)</span></span><br><span class="line"></span><br><span class="line">npm i hexo-renderer-pandoc --save</span><br></pre></td></tr></tbody></table></figure><p>前去官网安装pandoc,并保证能在命令行中运行<code>pandoc -v</code>.</p><p>2.文章的Front-matter里打开mathjax开关(一定要打开,不然不会渲染)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: index.html</span><br><span class="line">date: 2016-12-28 21:01:30</span><br><span class="line">tags:</span><br><span class="line">mathjax: true</span><br><span class="line">--</span><br></pre></td></tr></tbody></table></figure><p>至此可以完美渲染公式</p><p><strong>示例如下</strong></p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">$</span><span class="built_in">$</span><span class="keyword">\begin</span>{equation}</span><br><span class="line"><span class="keyword">\begin</span>{aligned}</span><br><span class="line">a <span class="built_in">&</span>= b + c <span class="keyword">\\</span></span><br><span class="line"> <span class="built_in">&</span>= d + e + f + g <span class="keyword">\\</span></span><br><span class="line"> <span class="built_in">&</span>= h + i</span><br><span class="line"><span class="keyword">\end</span>{aligned}</span><br><span class="line"><span class="keyword">\end</span>{equation}<span class="keyword">\label</span>{eq2}<span class="built_in">$</span><span class="built_in">$</span></span><br></pre></td></tr></tbody></table></figure><p><span class="math display">\[\begin{equation}\begin{aligned}a &= b + c \\ &= d + e + f + g \\ &= h + i\end{aligned}\end{equation}\label{eq2}\]</span></p><figure class="highlight latex"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">$</span>state <span class="keyword">\overset</span>{NN}{<span class="keyword">\rightarrow</span>}<span class="keyword">\left</span><span class="keyword">\{</span> <span class="keyword">\begin</span>{aligned} <span class="built_in">&</span>action1 <span class="keyword">\_</span> value <span class="keyword">\\</span> <span class="built_in">&</span>action2 <span class="keyword">\_</span> value <span class="keyword">\\</span> <span class="built_in">&</span>...<span class="keyword">\end</span>{aligned} <span class="keyword">\right</span>.<span class="built_in">$</span></span><br></pre></td></tr></tbody></table></figure><p><span class="math inline">\(state \overset{NN}{\rightarrow}\left\{\begin{aligned} &action1 \_ value \\ &action2 \_ value \\&...\end{aligned} \right.\)</span></p><h3 id="为标题增加序号">为标题增加序号</h3><p>修改<code>文件位置:themes\next\source\css\_custom\custom.styl</code></p><figure class="highlight stylus"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//文章标题增加序号</span></span><br><span class="line"><span class="selector-class">.post-body</span> {<span class="attribute">counter-reset</span>:section}</span><br><span class="line"><span class="selector-class">.post-body</span> h2{<span class="attribute">counter-reset</span>:sub-section}</span><br><span class="line"><span class="selector-class">.post-body</span> h3{<span class="attribute">counter-reset</span>:composite}</span><br><span class="line"><span class="selector-class">.post-body</span> h4{<span class="attribute">counter-reset</span>:detail}</span><br><span class="line"><span class="selector-class">.post-body</span> <span class="selector-tag">h2</span>:before{<span class="attribute">content</span>:<span class="built_in">counter</span>(section) <span class="string">" "</span>;<span class="attribute">counter-increment</span>:section}</span><br><span class="line"><span class="selector-class">.post-body</span> <span class="selector-tag">h3</span>:before{<span class="attribute">content</span>:<span class="built_in">counter</span>(section) <span class="string">"."</span> <span class="built_in">counter</span>(sub-section) <span class="string">" "</span>;<span class="attribute">counter-increment</span>:sub-section}</span><br><span class="line"><span class="selector-class">.post-body</span> <span class="selector-tag">h4</span>:before{<span class="attribute">content</span>:<span class="built_in">counter</span>(section) <span class="string">"."</span> <span class="built_in">counter</span>(sub-section) <span class="string">"."</span> <span class="built_in">counter</span>(composite) <span class="string">" "</span>;<span class="attribute">counter-increment</span>:composite}</span><br><span class="line"><span class="selector-class">.post-body</span> <span class="selector-tag">h5</span>:before{<span class="attribute">content</span>:<span class="built_in">counter</span>(section) <span class="string">"."</span> <span class="built_in">counter</span>(sub-section) <span class="string">"."</span> <span class="built_in">counter</span>(composite) <span class="string">"."</span> <span class="built_in">counter</span>(detail) <span class="string">" "</span>;<span class="attribute">counter-increment</span>:detail}</span><br></pre></td></tr></tbody></table></figure><h2 id="博客深度优化">博客深度优化</h2><h3 id="博文压缩">博文压缩</h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-neat --save</span><br><span class="line">npm install hexo-imagemin --save</span><br></pre></td></tr></tbody></table></figure><h3 id="脚本拼接">脚本拼接</h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-filter-optimize --save</span><br></pre></td></tr></tbody></table></figure><p>修改配置文件</p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">filter_optimize:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># remove static resource query string</span></span><br><span class="line"> <span class="comment"># - like `?v=1.0.0`</span></span><br><span class="line"> <span class="attr">remove_query_string:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># remove the surrounding comments in each of the bundled files</span></span><br><span class="line"> <span class="attr">remove_comments:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">css:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># bundle loaded css file into the one</span></span><br><span class="line"> <span class="attr">bundle:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># use a script block to load css elements dynamically</span></span><br><span class="line"> <span class="attr">delivery:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># make specific css content inline into the html page</span></span><br><span class="line"> <span class="comment"># - only support the full path</span></span><br><span class="line"> <span class="comment"># - default is ['css/main.css']</span></span><br><span class="line"> <span class="attr">inlines:</span></span><br><span class="line"> <span class="attr">excludes:</span></span><br><span class="line"> <span class="attr">js:</span></span><br><span class="line"> <span class="comment"># bundle loaded js file into the one</span></span><br><span class="line"> <span class="attr">bundle:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">excludes:</span></span><br><span class="line"> <span class="comment"># set the priority of this plugin,</span></span><br><span class="line"> <span class="comment"># lower means it will be executed first, default is 10</span></span><br><span class="line"> <span class="attr">priority:</span> <span class="number">12</span></span><br></pre></td></tr></tbody></table></figure><p>另外修改主题</p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">fontawesome:</span> <span class="string">//cdn.bootcss.com/font-awesome/4.6.2/css/font-awesome.min.css</span></span><br></pre></td></tr></tbody></table></figure><h3 id="增加建站时间">增加建站时间</h3><p>修改文件<code>blog/themes/next/layout/_custom/sidebar.swig</code></p><figure class="highlight js"><figcaption><span>blog/themes/next/layout/_custom/sidebar.swig</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><div id=<span class="string">"days"</span>></div></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">script</span>></span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">function</span> <span class="title function_">show_date_time</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">window</span>.<span class="built_in">setTimeout</span>(<span class="string">"show_date_time()"</span>, <span class="number">1000</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="title class_">BirthDay</span>=<span class="keyword">new</span> <span class="title class_">Date</span>(<span class="string">"1/15/2019 12:00:00"</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">today=<span class="keyword">new</span> <span class="title class_">Date</span>();</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">timeold=(today.<span class="title function_">getTime</span>()-<span class="title class_">BirthDay</span>.<span class="title function_">getTime</span>());</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">sectimeold=timeold/<span class="number">1000</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">secondsold=<span class="title class_">Math</span>.<span class="title function_">floor</span>(sectimeold);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">msPerDay=<span class="number">24</span>*<span class="number">60</span>*<span class="number">60</span>*<span class="number">1000</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_daysold=timeold/msPerDay</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">daysold=<span class="title class_">Math</span>.<span class="title function_">floor</span>(e_daysold);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_hrsold=(e_daysold-daysold)*<span class="number">24</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">hrsold=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>(e_hrsold));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_minsold=(e_hrsold-hrsold)*<span class="number">60</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">minsold=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>((e_hrsold-hrsold)*<span class="number">60</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">seconds=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>((e_minsold-minsold)*<span class="number">60</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'days'</span>).<span class="property">innerHTML</span>=<span class="string">"已运行 "</span>+daysold+<span class="string">" 天 "</span>+hrsold+<span class="string">" 小时 "</span>+minsold+<span class="string">" 分 "</span>+seconds+<span class="string">" 秒"</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">function</span> <span class="title function_">setzero</span>(<span class="params">i</span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">if</span> (i<<span class="number">10</span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">{i=<span class="string">"0"</span> + i};</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">return</span> i;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="title function_">show_date_time</span>();</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag"></<span class="name">script</span>></span></span></span><br></pre></td></tr></tbody></table></figure><h3 id="更换tag标签图标">更换tag标签图标</h3><figure class="highlight diff"><figcaption><span>themes/next/layout/_macro/post.swig</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="deletion">- rel="tag">#</span></span><br><span class="line"><span class="addition">+ rel="tag"><i class="fa fa-tag"></i></span></span><br></pre></td></tr></tbody></table></figure><h3 id="增加文字计数功能">增加文字计数功能</h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-symbols-count-time --save</span><br></pre></td></tr></tbody></table></figure><p>然后修改配置文件<code>blog/_config.yml</code>即可</p><h3 id="更换宋体2">更换宋体<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></h3><p>修改相应配置文件<code>themes/next/source/css/_variables/custom.styl</code>即可</p><figure class="highlight stylus"><figcaption><span>themes/next/source/css/_variables/custom.styl</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$font</span>-family-monospace = consolas, Menlo, <span class="variable">$font</span>-family-base, monospace</span><br><span class="line"><span class="variable">$font</span>-family-monospace = <span class="built_in">get_font_family</span>(<span class="string">'codes'</span>), consolas, Menlo, <span class="variable">$font</span>-family-base, monospace <span class="keyword">if</span> <span class="built_in">get_font_family</span>(<span class="string">'codes'</span>)</span><br><span class="line"></span><br><span class="line"><span class="variable">$font</span>-family-chinese = <span class="string">"Linux Biolinum"</span></span><br><span class="line"><span class="variable">$font</span>-family-base = <span class="variable">$font</span>-family-chinese, <span class="built_in">get_font_family</span>(<span class="string">'global'</span>), sans-serif <span class="keyword">if</span> <span class="built_in">get_font_family</span>(<span class="string">'global'</span>)</span><br></pre></td></tr></tbody></table></figure><p>增加字体文件<code>blog/source/fonts</code></p><h3 id="添加结束文字">添加结束文字</h3><p>TODO:用css实现</p><h3 id="文章置顶1">文章置顶<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a></h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ npm uninstall hexo-generator-index --save</span><br><span class="line">$ npm install hexo-generator-index-pin-top --save</span><br></pre></td></tr></tbody></table></figure><p>使用时同时添加下列两个标签</p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">top:</span> <span class="number">10</span></span><br><span class="line"><span class="attr">sticky:</span> <span class="literal">true</span></span><br></pre></td></tr></tbody></table></figure><p>在<code>next/source/css/_custom/custom.styl</code>自定义样式</p><figure class="highlight stylus"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 自定义的文章置顶样式</span></span><br><span class="line"><span class="selector-class">.post-sticky-flag</span> {</span><br><span class="line"> <span class="attribute">font-size</span>: <span class="number">18px</span>;</span><br><span class="line"> <span class="attribute">float</span>: left;</span><br><span class="line"> <span class="attribute">color</span>: <span class="built_in">rgb</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> <span class="attribute">cursor</span>: help;</span><br><span class="line"> <span class="attribute">transition-duration</span>: <span class="number">0.2s</span>;</span><br><span class="line"> <span class="attribute">transition-timing-function</span>: ease-in-out;</span><br><span class="line"> <span class="attribute">transition-delay</span>: <span class="number">0s</span>;</span><br><span class="line">}</span><br><span class="line"><span class="selector-class">.post-sticky-flag</span><span class="selector-pseudo">:hover</span> {</span><br><span class="line"> <span class="attribute">color</span>: <span class="number">#07b39b</span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="生成唯一链接">生成唯一链接</h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-abbrlink --save</span><br></pre></td></tr></tbody></table></figure><h2 id="配置文件附下">配置文件附下</h2><h3 id="blog_config.yml"><code>blog/_config.yml</code></h3><figure class="highlight yml"><figcaption><span>blog/_config.yml</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Hexo Configuration</span></span><br><span class="line"><span class="comment">## Docs: https://hexo.io/docs/configuration.html</span></span><br><span class="line"><span class="comment">## Source: https://github.com/hexojs/hexo/</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Site</span></span><br><span class="line"><span class="attr">title:</span> <span class="string">s0mE</span></span><br><span class="line"><span class="attr">subtitle:</span> <span class="string">Less</span> <span class="string">is</span> <span class="string">More</span></span><br><span class="line"><span class="attr">description:</span> <span class="string">Less</span> <span class="string">is</span> <span class="string">More</span></span><br><span class="line"><span class="attr">keywords:</span></span><br><span class="line"><span class="attr">author:</span> <span class="string">Lingjia</span> <span class="string">Meng</span></span><br><span class="line"><span class="attr">language:</span> <span class="string">zh-CN</span></span><br><span class="line"><span class="attr">timezone:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># URL</span></span><br><span class="line"><span class="comment">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</span></span><br><span class="line"><span class="attr">url:</span> <span class="string">http://s0me.top</span></span><br><span class="line"><span class="attr">root:</span> <span class="string">/</span></span><br><span class="line"><span class="attr">permalink:</span> <span class="string">:year/:month/:day/:title/</span></span><br><span class="line"><span class="attr">permalink_defaults:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Directory</span></span><br><span class="line"><span class="attr">source_dir:</span> <span class="string">source</span></span><br><span class="line"><span class="attr">public_dir:</span> <span class="string">public</span></span><br><span class="line"><span class="attr">tag_dir:</span> <span class="string">tags</span></span><br><span class="line"><span class="attr">archive_dir:</span> <span class="string">archives</span></span><br><span class="line"><span class="attr">category_dir:</span> <span class="string">categories</span></span><br><span class="line"><span class="attr">code_dir:</span> <span class="string">downloads/code</span></span><br><span class="line"><span class="attr">i18n_dir:</span> <span class="string">:lang</span></span><br><span class="line"><span class="attr">skip_render:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Writing</span></span><br><span class="line"><span class="attr">new_post_name:</span> <span class="string">:title.md</span> <span class="comment"># File name of new posts</span></span><br><span class="line"><span class="attr">default_layout:</span> <span class="string">post</span></span><br><span class="line"><span class="attr">titlecase:</span> <span class="literal">false</span> <span class="comment"># Transform title into titlecase</span></span><br><span class="line"><span class="attr">external_link:</span> <span class="literal">true</span> <span class="comment"># Open external links in new tab</span></span><br><span class="line"><span class="attr">filename_case:</span> <span class="number">0</span></span><br><span class="line"><span class="attr">render_drafts:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">post_asset_folder:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">relative_link:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">future:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">highlight:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">line_number:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">auto_detect:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">tab_replace:</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># Home page setting</span></span><br><span class="line"><span class="comment"># path: Root path for your blogs index page. (default = '')</span></span><br><span class="line"><span class="comment"># per_page: Posts displayed per page. (0 = disable pagination)</span></span><br><span class="line"><span class="comment"># order_by: Posts order. (Order by date descending by default)</span></span><br><span class="line"><span class="attr">index_generator:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">''</span></span><br><span class="line"> <span class="attr">per_page:</span> <span class="number">10</span></span><br><span class="line"> <span class="attr">order_by:</span> <span class="string">-date</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># Category & Tag</span></span><br><span class="line"><span class="attr">default_category:</span> <span class="string">uncategorized</span></span><br><span class="line"><span class="attr">category_map:</span></span><br><span class="line"><span class="attr">tag_map:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Date / Time format</span></span><br><span class="line"><span class="comment">## Hexo uses Moment.js to parse and display date</span></span><br><span class="line"><span class="comment">## You can customize the date format as defined in</span></span><br><span class="line"><span class="comment">## http://momentjs.com/docs/#/displaying/format/</span></span><br><span class="line"><span class="attr">date_format:</span> <span class="string">YYYY-MM-DD</span></span><br><span class="line"><span class="attr">time_format:</span> <span class="string">HH:mm:ss</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Pagination</span></span><br><span class="line"><span class="comment">## Set per_page to 0 to disable pagination</span></span><br><span class="line"><span class="attr">per_page:</span> <span class="number">10</span></span><br><span class="line"><span class="attr">pagination_dir:</span> <span class="string">page</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Extensions</span></span><br><span class="line"><span class="comment">## Plugins: https://hexo.io/plugins/</span></span><br><span class="line"><span class="comment">## Themes: https://hexo.io/themes/</span></span><br><span class="line"><span class="attr">theme:</span> <span class="string">next</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Deployment</span></span><br><span class="line"><span class="comment">## Docs: https://hexo.io/docs/deployment.html</span></span><br><span class="line"><span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line"> <span class="attr">repo:</span> <span class="string">[email protected]:lingjiameng/lingjiameng.github.io.git</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">master</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#本地搜索</span></span><br><span class="line"><span class="attr">search:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">search.xml</span></span><br><span class="line"> <span class="attr">field:</span> <span class="string">post</span></span><br><span class="line"> <span class="attr">format:</span> <span class="string">html</span></span><br><span class="line"> <span class="attr">limit:</span> <span class="number">10000</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 博文压缩</span></span><br><span class="line"><span class="comment"># hexo-neat</span></span><br><span class="line"><span class="attr">neat_enable:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="attr">neat_html:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">exclude:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/lib/pdf/web/viewer.html'</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">neat_css:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">exclude:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/*.min.css'</span></span><br><span class="line"></span><br><span class="line"><span class="attr">neat_js:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">mangle:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">output:</span></span><br><span class="line"> <span class="attr">compress:</span></span><br><span class="line"> <span class="attr">exclude:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/*.min.js'</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/jquery.fancybox.pack.js'</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/index.js'</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">'**/lib/pdf/web/debugger.js'</span> </span><br><span class="line"></span><br><span class="line"><span class="attr">imagemin:</span></span><br><span class="line"> <span class="attr">enable :</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">interlaced :</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">multipass :</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">optimizationLevel:</span> <span class="number">2</span></span><br><span class="line"> <span class="attr">pngquant :</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">progressive:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 计数插件</span></span><br><span class="line"><span class="attr">symbols_count_time:</span></span><br><span class="line"> <span class="attr">symbols:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">time:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">total_symbols:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">total_time:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">exclude_codeblock:</span> <span class="literal">false</span></span><br></pre></td></tr></tbody></table></figure><h3 id="blogthemesnext_config.yml"><code>blog/themes/next/_config.yml</code></h3><figure class="highlight yaml"><figcaption><span>blog/themes/next/_config.yml</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">footer:</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">since:</span> <span class="number">2019</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># Icon between year and copyright info.</span></span><br><span class="line"> <span class="attr">icon:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">heart</span></span><br><span class="line"> <span class="comment"># If you want to animate the icon, set it to true.</span></span><br><span class="line"> <span class="attr">animated:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Change the color of icon, using Hex Code.</span></span><br><span class="line"> <span class="attr">color:</span> <span class="string">"#ff0000"</span> <span class="comment"># "#808080"</span></span><br><span class="line"> <span class="attr">powered:</span></span><br><span class="line"> <span class="comment"># Hexo link (Powered by Hexo).</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Version info of Hexo after Hexo link (vX.X.X).</span></span><br><span class="line"> <span class="attr">version:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"> <span class="attr">theme:</span></span><br><span class="line"> <span class="comment"># Theme & scheme info link (Theme - NexT.scheme).</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Version info of NexT after scheme info (vX.X.X).</span></span><br><span class="line"> <span class="attr">version:</span> <span class="literal">true</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Menu Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="attr">menu:</span></span><br><span class="line"> <span class="attr">home:</span> <span class="string">/</span> <span class="string">||</span> <span class="string">home</span></span><br><span class="line"> <span class="attr">about:</span> <span class="string">/about/</span> <span class="string">||</span> <span class="string">user</span></span><br><span class="line"> <span class="attr">tags:</span> <span class="string">/tags/</span> <span class="string">||</span> <span class="string">tags</span></span><br><span class="line"> <span class="attr">categories:</span> <span class="string">/categories/</span> <span class="string">||</span> <span class="string">th</span></span><br><span class="line"> <span class="attr">archives:</span> <span class="string">/archives/</span> <span class="string">||</span> <span class="string">archive</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Scheme Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="attr">scheme:</span> <span class="string">Gemini</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Sidebar Settings</span></span><br><span class="line"><span class="comment"># See: https://theme-next.org/docs/theme-settings/sidebar</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Posts / Categories / Tags in sidebar.</span></span><br><span class="line"><span class="attr">site_state:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="attr">social:</span></span><br><span class="line"> <span class="attr">GitHub:</span> <span class="string">https://github.com/lingjiameng</span> <span class="string">||</span> <span class="string">github</span></span><br><span class="line"> <span class="attr">QQmail:</span> <span class="string">mailto:[email protected]</span> <span class="string">||</span> <span class="string">envelope</span></span><br><span class="line"> <span class="attr">Gmail:</span> <span class="string">mailto:[email protected]</span> <span class="string">||</span> <span class="string">google</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">social_icons:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">icons_only:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">transition:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Sidebar Avatar</span></span><br><span class="line"><span class="attr">avatar:</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">/images/s0mE.jpg</span> <span class="comment">#/images/avatar.gif</span></span><br><span class="line"></span><br><span class="line"><span class="attr">back2top:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Back to top in sidebar.</span></span><br><span class="line"> <span class="attr">sidebar:</span> <span class="literal">false</span></span><br><span class="line"> <span class="comment"># Scroll percent label in b2t button.</span></span><br><span class="line"> <span class="attr">scrollpercent:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># Automatically scroll page to section which is under <!-- more --> mark.</span></span><br><span class="line"><span class="attr">scroll_to_more:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Automatically saving scroll position on each post / page in cookies.</span></span><br><span class="line"><span class="attr">save_scroll:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Automatically excerpt description in homepage as preamble text.</span></span><br><span class="line"><span class="attr">excerpt_description:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Automatically Excerpt (Not recommend).</span></span><br><span class="line"><span class="comment"># Use <!-- more --> in the post to control excerpt accurately.</span></span><br><span class="line"><span class="attr">auto_excerpt:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">length:</span> <span class="number">150</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Read more button</span></span><br><span class="line"><span class="comment"># If true, the read more button would be displayed in excerpt section.</span></span><br><span class="line"><span class="attr">read_more_btn:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Post meta display settings</span></span><br><span class="line"><span class="attr">post_meta:</span></span><br><span class="line"> <span class="attr">item_text:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">created_at:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">updated_at:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">another_day:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">categories:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Post wordcount display settings</span></span><br><span class="line"><span class="comment"># Dependencies: https://github.com/theme-next/hexo-symbols-count-time</span></span><br><span class="line"><span class="attr">symbols_count_time:</span></span><br><span class="line"> <span class="attr">separated_meta:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">item_text_post:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">item_text_total:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">awl:</span> <span class="number">4</span></span><br><span class="line"> <span class="attr">wpm:</span> <span class="number">275</span></span><br><span class="line"></span><br><span class="line"><span class="attr">codeblock:</span></span><br><span class="line"> <span class="comment"># Manual define the border radius in codeblock, leave it blank for the default value: 1</span></span><br><span class="line"> <span class="attr">border_radius:</span> </span><br><span class="line"> <span class="comment"># Add copy button on codeblock</span></span><br><span class="line"> <span class="attr">copy_button:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Show text copy result</span></span><br><span class="line"> <span class="attr">show_result:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Style: only 'flat' is currently available, leave it blank if you prefer default theme</span></span><br><span class="line"> <span class="attr">style:</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Related popular posts</span></span><br><span class="line"><span class="comment"># Dependencies: https://github.com/tea3/hexo-related-popular-posts</span></span><br><span class="line"><span class="attr">related_posts:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">title:</span> <span class="string">相关文章</span> <span class="comment"># custom header, leave empty to use the default one</span></span><br><span class="line"> <span class="attr">display_in_home:</span> <span class="literal">false</span></span><br><span class="line"> <span class="attr">params:</span></span><br><span class="line"> <span class="attr">maxCount:</span> <span class="number">5</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Code Highlight theme</span></span><br><span class="line"><span class="attr">highlight_theme:</span> <span class="string">night</span> <span class="string">eighties</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># TagCloud settings for tags page.</span></span><br><span class="line"><span class="attr">tagcloud:</span></span><br><span class="line"> <span class="comment"># If true, font size, font color and amount of tags can be customized</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># All values below are same as default, change them by yourself</span></span><br><span class="line"> <span class="attr">min:</span> <span class="number">12</span> <span class="comment"># min font size in px</span></span><br><span class="line"> <span class="attr">max:</span> <span class="number">30</span> <span class="comment"># max font size in px</span></span><br><span class="line"> <span class="attr">start:</span> <span class="string">"#9733EE"</span> <span class="comment"># start color (hex, rgba, hsla or color keywords)</span></span><br><span class="line"> <span class="attr">end:</span> <span class="string">"#FF512F"</span> <span class="comment"># end color (hex, rgba, hsla or color keywords)</span></span><br><span class="line"> <span class="attr">amount:</span> <span class="number">200</span> <span class="comment"># amount of tags, change it if you have more than 200 tags</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Font Settings. Introduced in NexT v5.0.1.</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="attr">font:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="string">true.</span></span><br><span class="line"> <span class="attr">host:</span> <span class="string">https://fonts.loli.net</span></span><br><span class="line"> <span class="attr">global:</span></span><br><span class="line"> <span class="attr">external:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">family:</span> <span class="string">Noto</span> <span class="string">Serif</span> <span class="string">SC</span> <span class="comment">#Lato</span></span><br><span class="line"> <span class="attr">size:</span> <span class="number">16</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Third Party Services Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Math Equations Render Support</span></span><br><span class="line"><span class="attr">math:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">per_page:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">engine:</span> <span class="string">mathjax</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Han Support</span></span><br><span class="line"><span class="comment"># Dependencies: https://github.com/theme-next/theme-next-han</span></span><br><span class="line"><span class="attr">han:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Content Sharing Services</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="attr">needmoreshare2:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">postbottom:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">options:</span></span><br><span class="line"> <span class="attr">iconStyle:</span> <span class="string">box</span></span><br><span class="line"> <span class="attr">boxForm:</span> <span class="string">horizontal</span></span><br><span class="line"> <span class="attr">position:</span> <span class="string">bottomCenter</span></span><br><span class="line"> <span class="attr">networks:</span> <span class="string">Weibo,Wechat,Douban,QQZone,Twitter,Facebook</span></span><br><span class="line"> <span class="attr">float:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">options:</span></span><br><span class="line"> <span class="attr">iconStyle:</span> <span class="string">box</span></span><br><span class="line"> <span class="attr">boxForm:</span> <span class="string">horizontal</span></span><br><span class="line"> <span class="attr">position:</span> <span class="string">middleRight</span></span><br><span class="line"> <span class="attr">networks:</span> <span class="string">Weibo,Wechat,Douban,QQZone,Twitter,Facebook</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Search Services</span></span><br><span class="line"><span class="comment"># See: https://theme-next.org/docs/third-party-services/search-services</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Local search</span></span><br><span class="line"><span class="comment"># Dependencies: https://github.com/theme-next/hexo-generator-searchdb</span></span><br><span class="line"><span class="attr">local_search:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># If auto, trigger search by changing input.</span></span><br><span class="line"> <span class="comment"># If manual, trigger search by pressing enter key or search button.</span></span><br><span class="line"> <span class="attr">trigger:</span> <span class="string">auto</span></span><br><span class="line"> <span class="comment"># Show top n results per article, show all results by setting to -1</span></span><br><span class="line"> <span class="attr">top_n_per_article:</span> <span class="number">1</span></span><br><span class="line"> <span class="comment"># Unescape html strings to the readable one.</span></span><br><span class="line"> <span class="attr">unescape:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># tag Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pdf:</span></span><br><span class="line"> <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># Default height</span></span><br><span class="line"> <span class="attr">height:</span> <span class="string">600px</span></span><br><span class="line"> <span class="attr">pdfobject:</span></span><br><span class="line"> <span class="attr">cdn:</span> <span class="string">//cdn.jsdelivr.net/npm/pdfobject@2/pdfobject.min.js</span></span><br><span class="line"> <span class="comment">#cdn: </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># Animation Settings</span></span><br><span class="line"><span class="comment"># ---------------------------------------------------------------</span></span><br><span class="line"><span class="attr">pace:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">pace_theme:</span> <span class="string">pace-theme-minimal</span></span><br></pre></td></tr></tbody></table></figure><h3 id="blogthemesnextlayout_customsidebar.swig"><code>blog/themes/next/layout/_custom/sidebar.swig</code></h3><figure class="highlight js"><figcaption><span>blog/themes/next/layout/_custom/sidebar.swig</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><div id=<span class="string">"days"</span>></div></span><br><span class="line"><span class="language-xml"><span class="tag"><<span class="name">script</span>></span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">function</span> <span class="title function_">show_date_time</span>(<span class="params"></span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">window</span>.<span class="built_in">setTimeout</span>(<span class="string">"show_date_time()"</span>, <span class="number">1000</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="title class_">BirthDay</span>=<span class="keyword">new</span> <span class="title class_">Date</span>(<span class="string">"1/15/2019 12:00:00"</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">today=<span class="keyword">new</span> <span class="title class_">Date</span>();</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">timeold=(today.<span class="title function_">getTime</span>()-<span class="title class_">BirthDay</span>.<span class="title function_">getTime</span>());</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">sectimeold=timeold/<span class="number">1000</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">secondsold=<span class="title class_">Math</span>.<span class="title function_">floor</span>(sectimeold);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">msPerDay=<span class="number">24</span>*<span class="number">60</span>*<span class="number">60</span>*<span class="number">1000</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_daysold=timeold/msPerDay</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">daysold=<span class="title class_">Math</span>.<span class="title function_">floor</span>(e_daysold);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_hrsold=(e_daysold-daysold)*<span class="number">24</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">hrsold=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>(e_hrsold));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">e_minsold=(e_hrsold-hrsold)*<span class="number">60</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">minsold=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>((e_hrsold-hrsold)*<span class="number">60</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">seconds=<span class="title function_">setzero</span>(<span class="title class_">Math</span>.<span class="title function_">floor</span>((e_minsold-minsold)*<span class="number">60</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">'days'</span>).<span class="property">innerHTML</span>=<span class="string">"已运行 "</span>+daysold+<span class="string">" 天 "</span>+hrsold+<span class="string">" 小时 "</span>+minsold+<span class="string">" 分 "</span>+seconds+<span class="string">" 秒"</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">function</span> <span class="title function_">setzero</span>(<span class="params">i</span>){</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">if</span> (i<<span class="number">10</span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">{i=<span class="string">"0"</span> + i};</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="keyword">return</span> i;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">}</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"><span class="title function_">show_date_time</span>();</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag"></<span class="name">script</span>></span></span></span><br></pre></td></tr></tbody></table></figure><h3 id="hemesnextsourcecss_variablescustom.styl"><code>hemes/next/source/css/_variables/custom.styl</code></h3><figure class="highlight stylus"><figcaption><span>hemes/next/source/css/_variables/custom.styl</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$font</span>-family-monospace = consolas, Menlo, <span class="variable">$font</span>-family-base, monospace</span><br><span class="line"><span class="variable">$font</span>-family-monospace = <span class="built_in">get_font_family</span>(<span class="string">'codes'</span>), consolas, Menlo, <span class="variable">$font</span>-family-base, monospace <span class="keyword">if</span> <span class="built_in">get_font_family</span>(<span class="string">'codes'</span>)</span><br><span class="line"></span><br><span class="line"><span class="variable">$font</span>-family-chinese = <span class="string">"Linux Biolinum"</span></span><br><span class="line"><span class="variable">$font</span>-family-base = <span class="variable">$font</span>-family-chinese, <span class="built_in">get_font_family</span>(<span class="string">'global'</span>), sans-serif <span class="keyword">if</span> <span class="built_in">get_font_family</span>(<span class="string">'global'</span>)</span><br></pre></td></tr></tbody></table></figure><h2 id="修改过的文件">修改过的文件</h2><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 安装hexo</span></span><br><span class="line">hexo new page tags</span><br><span class="line">hexo new page categories</span><br><span class="line">hexo new page about</span><br><span class="line"><span class="comment"># 安装next</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 资源文件</span></span><br><span class="line">blog/source/fonts <span class="comment">#增加字体</span></span><br><span class="line">themes/next/source/images <span class="comment">#增加头像 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置文件</span></span><br><span class="line">blog/_config.yml</span><br><span class="line">blog/themes/next/_config.yml</span><br><span class="line">blog/themes/next/layout/_custom/sidebar.swig <span class="comment">#计时功能</span></span><br><span class="line">themes/next/source/css/_variables/custom.styl <span class="comment">#字体调整</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># npm安装博客根目录操作</span></span><br><span class="line">npm install hexo-deployer-git --save</span><br><span class="line">npm install hexo-related-popular-posts --save</span><br><span class="line">npm install hexo-generator-searchdb --save</span><br><span class="line">npm install hexo-asset-image-fixed --save</span><br><span class="line">npm install hexo-generator-feed --save</span><br><span class="line">npm uninstall hexo-generator-index --save</span><br><span class="line">npm install hexo-generator-index-pin-top --save</span><br><span class="line">npm install hexo-generator-sitemap --save</span><br><span class="line">npm install hexo-abbrlink --save</span><br><span class="line">npm install hexo-generator-baidu-sitemap --save</span><br><span class="line">npm install hexo-symbols-count-time --save</span><br><span class="line"></span><br><span class="line"><span class="comment">#主题插件git下载,切入主题目录下操作</span></span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-needmoreshare2 <span class="built_in">source</span>/lib/needsharebutton</span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-pdf <span class="built_in">source</span>/lib/pdf</span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-fancybox3 <span class="built_in">source</span>/lib/fancybox</span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-pace <span class="built_in">source</span>/lib/pace</span><br><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/theme-next-han <span class="built_in">source</span>/lib/Han</span><br><span class="line"></span><br><span class="line"><span class="comment">#源文件</span></span><br><span class="line">themes/next/layout/_macro/post.swig</span><br><span class="line"><span class="comment"># - rel="tag">#</span></span><br><span class="line"><span class="comment"># + rel="tag"><i class="fa fa-tag"></i></span></span><br></pre></td></tr></tbody></table></figure><section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"><hr><ol><li id="fn1"><p><a target="_blank" rel="noopener" href="https://io-oi.me/beautiful/share/2018/12/11/noto-serif-sc-added-on-google-fonts.html" class="uri">https://io-oi.me/beautiful/share/2018/12/11/noto-serif-sc-added-on-google-fonts.html</a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li><li id="fn2"><p>https://blog.csdn.net/qwerty200696/article/details/79010629<a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li></ol></section></body></html>]]></content>
<summary type="html"><html><head></head><body><h2 id="安装hexo">安装hexo</h2>
<figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g hexo-cli</span><br><span class="line"></span><br><span class="line"><span class="comment"># Hexo 将会在指定文件夹中新建所需要的文件</span></span><br><span class="line">$ hexo init &lt;folder&gt;</span><br><span class="line">$ <span class="built_in">cd</span> &lt;folder&gt;</span><br><span class="line">$ npm install</span><br><span class="line"></span><br><span class="line"><span class="comment">#安装git</span></span><br><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></tbody></table></figure>
<h2 id="安装next主题">安装NexT主题</h2>
<p><a target="_blank" rel="noopener" href="https://github.com/theme-next/hexo-theme-next/blob/master/docs/INSTALLATION.md">参考链接</a></p>
<figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">mkdir</span> themes/next</span><br><span class="line">$ curl -s https://api.github.com/repos/theme-next/hexo-theme-next/releases/latest | grep tarball_url | <span class="built_in">cut</span> -d <span class="string">'"'</span> -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1</span><br></pre></td></tr></tbody></table></figure></body></html></summary>
<category term="hexo" scheme="http://ljmeng.site/tags/hexo/"/>
<category term="next" scheme="http://ljmeng.site/tags/next/"/>
</entry>
<entry>
<title>服务器远程登录配置</title>
<link href="http://ljmeng.site/posts/38376/"/>
<id>http://ljmeng.site/posts/38376/</id>
<published>2019-03-09T08:48:02.000Z</published>
<updated>2019-03-09T08:48:02.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p>这是一篇首次使用高性能服务器的记录,包含linux和windows</p><figure><img src="/posts/38376/ssh.png" alt="ssh"><figcaption aria-hidden="true">ssh</figcaption></figure><span id="more"></span><h2 id="linux">linux</h2><p><strong>方案:</strong> <span id="inline-blue">ssh + scp</span></p><p>简介: 使用ssh实现无密码安全登录,scp实现文件传输</p><h3 id="ssh">ssh</h3><p>只需要用到两个命令</p><ul><li><code>ssh-keygen</code> 生成公钥、私钥</li><li><code>ssh-copy-id</code> 上传公钥到服务器</li></ul><h4 id="参数详解">参数详解</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$ ssh-keygen (选项)</span><br><span class="line"></span><br><span class="line">-b:指定密钥长度;</span><br><span class="line">-e:读取openssh的私钥或者公钥文件;</span><br><span class="line">-C:添加注释;</span><br><span class="line">-f:指定用来保存密钥的文件名;</span><br><span class="line">-i:读取未加密的ssh-v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥;</span><br><span class="line">-l:显示公钥文件的指纹数据;</span><br><span class="line">-N:提供一个新密语;</span><br><span class="line">-P:提供(旧)密语;</span><br><span class="line">-q:静默模式;</span><br><span class="line">-t:指定要创建的密钥类型。</span><br><span class="line"></span><br><span class="line">$ ssh-copy-id [-i [identity_file]] [user@]machine</span><br><span class="line">-i:指定公钥文件</span><br></pre></td></tr></tbody></table></figure><h4 id="tips">tips:</h4><ul><li><code>ssh-copy-id</code> 命令会把本地主机的公钥复制到远程主机的<code>authorized_keys</code>文件中,</li><li>ssh-copy-id命令也会给远程主机的用户主目录和<code>~/.ssh</code>,和<code>~/.ssh/authorized_keys</code>设置合适的权限。</li><li>删除已配置好的秘钥只需删除 <code>~/.ssh</code>文件即可</li></ul><h4 id="实际命令">实际命令</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">$ ssh-keygen -t rsa <span class="comment"># 使用RSA算法创建私钥和公钥</span></span><br><span class="line"><span class="comment"># 输出如下</span></span><br><span class="line"><span class="comment"># Generating public/private rsa key pair.</span></span><br><span class="line"><span class="comment"># Enter file in which to save the key (/home/matrix/.ssh/id_rsa): 输入秘钥文件名</span></span><br><span class="line"><span class="comment"># 上面一行如果没用过秘钥就直接enter,若有多个秘钥建议改名,默认生成至家目录(~/)下</span></span><br><span class="line"><span class="comment"># 我使用 simplehpc (服务器的名字)</span></span><br><span class="line"><span class="comment"># Enter passphrase (empty for no passphrase): 输入一个密码</span></span><br><span class="line"><span class="comment"># Enter same passphrase again: 再次输入密码</span></span><br><span class="line"><span class="comment"># 密码用于加密私钥和公钥,建议输入</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 上一条命令若未改名,直接执行此命令,输入密码即可成功</span></span><br><span class="line">$ ssh-copy-id username@remote-server</span><br><span class="line"></span><br><span class="line"><span class="comment"># 若改名 则执行下列命令</span></span><br><span class="line"><span class="variable">$ssh</span>-copy-id -i 公钥路径 username@remote-server</span><br><span class="line"><span class="comment"># 公钥后缀为 .pub ,我的公钥位于 ~/.ssh/simplehpc.pub ,所以我的命令如下</span></span><br><span class="line"><span class="comment"># ssh-copy-id -i ~/.ssh/simplehpc.pub username@remote-server</span></span><br></pre></td></tr></tbody></table></figure><h3 id="scp">scp</h3><p>scp(跨机远程拷贝)是securecopy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的。</p><h4 id="参数详解-1">参数详解</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">$ scp [参数] [原路径] [目标路径]</span><br><span class="line"></span><br><span class="line">-1 强制scp命令使用协议ssh1</span><br><span class="line">-2 强制scp命令使用协议ssh2</span><br><span class="line">-4 强制scp命令只使用IPv4寻址</span><br><span class="line">-6 强制scp命令只使用IPv6寻址</span><br><span class="line">-B 使用批处理模式(传输过程中不询问传输口令或短语)</span><br><span class="line">-C 允许压缩。(将-C标志传递给ssh,从而打开压缩功能)</span><br><span class="line">-p 留原文件的修改时间,访问时间和访问权限。</span><br><span class="line">-q 不显示传输进度条。</span><br><span class="line">-r 递归复制整个目录。</span><br><span class="line">-v 详细方式显示输出。scp和ssh(1)会显示出整个过程的调试信息。这些信息用于调试连接,验证和配置问题。</span><br><span class="line">-c cipher 以cipher将数据传输进行加密,这个选项将直接传递给ssh。</span><br><span class="line">-F ssh_config 指定一个替代的ssh配置文件,此参数直接传递给ssh。</span><br><span class="line">-i identity_file 从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh。</span><br><span class="line">-l <span class="built_in">limit</span> 限定用户所能使用的带宽,以Kbit/s为单位。</span><br><span class="line">-o ssh_option 如果习惯于使用ssh_config(5)中的参数传递方式,</span><br><span class="line">-P port 注意是大写的P, port是指定数据传输用到的端口号</span><br><span class="line">-S program 指定加密传输时所使用的程序。此程序必须能够理解ssh(1)的选项。</span><br></pre></td></tr></tbody></table></figure><h4 id="命令示例">命令示例</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 复制文件</span></span><br><span class="line">$ scp local_file remote_username@remote_ip:remote_folder</span><br><span class="line">$ scp local_file remote_username@remote_ip:remote_file</span><br><span class="line">$ scp local_file remote_ip:remote_folder</span><br><span class="line">$ scp local_file remote_ip:remote_file</span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定了用户名,命令执行后需要输入用户密码;</span></span><br><span class="line"><span class="comment"># 如果不指定用户名,命令执行后需要输入用户名和密码</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 复制目录</span></span><br><span class="line"><span class="variable">$scp</span> -r local_folder remote_username@remote_ip:remote_folder</span><br><span class="line"><span class="variable">$scp</span> -r local_folder remote_ip:remote_folder</span><br></pre></td></tr></tbody></table></figure><h2 id="windows">windows</h2><p><strong>方案:</strong> <span id="inline-blue">putty +filezilla</span></p><h2 id="参考链接">参考链接</h2><ul><li><a target="_blank" rel="noopener" href="https://www.linuxdashen.com/ssh-key%EF%BC%9A%E4%B8%A4%E4%B8%AA%E7%AE%80%E5%8D%95%E6%AD%A5%E9%AA%A4%E5%AE%9E%E7%8E%B0ssh%E6%97%A0%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95">两个简单步骤实现ssh无密码登录</a></li><li><a target="_blank" rel="noopener" href="http://man.linuxde.net/ssh-keygen">ssh命令文档</a></li><li><a target="_blank" rel="noopener" href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/scp.html">scp命令文档</a></li></ul></body></html>]]></content>
<summary type="html"><html><head></head><body><p>这是一篇首次使用高性能服务器的记录,包含linux和windows</p>
<figure>
<img src="/posts/38376/ssh.png" alt="ssh">
<figcaption aria-hidden="true">ssh</figcaption>
</figure></body></html></summary>
<category term="remote access" scheme="http://ljmeng.site/categories/remote-access/"/>
<category term="ssh" scheme="http://ljmeng.site/categories/ssh/"/>
<category term="linux" scheme="http://ljmeng.site/tags/linux/"/>
<category term="ssh" scheme="http://ljmeng.site/tags/ssh/"/>
<category term="scp" scheme="http://ljmeng.site/tags/scp/"/>
</entry>
<entry>
<title>ubuntu18.04个性化</title>
<link href="http://ljmeng.site/posts/38710/"/>
<id>http://ljmeng.site/posts/38710/</id>
<published>2019-03-02T08:25:01.000Z</published>
<updated>2019-03-02T08:25:01.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><p><strong>Ubuntu 18.04 个性化(持续更新)</strong></p><figure><img src="/posts/38710/1560660828546.png" alt="desktop"><figcaption aria-hidden="true">desktop</figcaption></figure><span id="more"></span><h2 id="百度网盘官方linux客户端安装">百度网盘官方Linux客户端安装</h2><p>1.<a target="_blank" rel="noopener" href="https://pan.baidu.com/download">官网</a>下载客户端</p><p>2.由于Ubuntu不支持rpm包安装,需要进行转换</p><p>安装转换工具</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install rpm alien fakeroot</span><br></pre></td></tr></tbody></table></figure><p>3.对包进行转换</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fakeroot alien -d baidunetdisk_linux_2.0.1.rpm</span><br></pre></td></tr></tbody></table></figure><p>4.安装deb包</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo dpkg -i baidunetdisk_2.0.1-2_amd64.deb</span><br></pre></td></tr></tbody></table></figure><p>至此安装就结束了,可以在应用列表里找到百度云</p><blockquote><p>附: 我转换好的deb包 链接:https://pan.baidu.com/s/15OsdXZJEZkgoQze22FlH8A 密码: qdem</p></blockquote><h2 id="网易云音乐安装与启动修复">网易云音乐安装与启动修复</h2><p><span id="inline-blue">2019-03-10更新:更新了启动脚本,不再需要sudo权限和密码</span></p><p><span id="inline-blue">2019-03-13更新:更新了启动脚本,可缩放网易云字体至合适大小</span></p><p><strong>第一次遇到此问题请直接跳至新版方案,无需看旧版方案</strong></p><h3 id="旧版方案">旧版方案</h3><p>1.<a target="_blank" rel="noopener" href="https://music.163.com/#/download">官方网站</a>下载安装</p><p>2.安装好后,发现网易云音乐无法正常打开。但是通过<code>sudo</code>命令可以启动。由此我想出了如下临时解决方案[step3-6]。</p><p>3.在<code>~/.bashrc</code>末尾行添加<code>alias music='. .music.sh'</code> <strong>注意为两个点且中间一个空格</strong> (music可替换为任意你想用的命令)</p><p>4.在 <code>~/</code> 创建文件 <code>.music.sh</code>(可以改为其他名字,只需记得同时修改步骤一的名字即可)文件内容如下,<code>password</code>需要改为你的密码</p><figure class="highlight bash"><figcaption><span>[2019.3.3更新]</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"password"</span> | sudo -S netease-cloud-music &</span><br><span class="line"><span class="built_in">sleep</span> 0.1 <span class="comment">#避免 终端未能及时输入密码就退出,而导致启动失败</span></span><br><span class="line"><span class="built_in">exit</span> 0</span><br></pre></td></tr></tbody></table></figure><p>5.重启计算机,或者在当前终端输入命令<code>source ~/.bashrc</code>使步骤1中的别名生效</p><p>6.输入命令 <code>music</code>就可以启动网易云音乐了。<strong>同时终端会自动关闭</strong></p><h3 id="新版方案">新版方案</h3><p>参考自大佬的<a target="_blank" rel="noopener" href="https://www.zhihu.com/question/277330447/answer/478510195">发现</a>,无需sudo权限和密码即可执行.</p><p><strong>对于使用过旧版方案的同学,请先执行以下命令</strong></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 修改文件所属用户和组以及权限</span></span><br><span class="line">sudo <span class="built_in">chmod</span> -R <span class="variable">${USER}</span>:<span class="variable">${USER}</span> ~/.config/netease-cloud-music</span><br><span class="line">sudo <span class="built_in">chmod</span> -R <span class="variable">${USER}</span>:<span class="variable">${USER}</span> ~/.cache/netease-cloud-music</span><br><span class="line"></span><br><span class="line">sudo <span class="built_in">chmod</span> 755 -R ~/.config/netease-cloud-music</span><br><span class="line">sudo <span class="built_in">chmod</span> 755 -R ~/.cache/netease-cloud-music</span><br><span class="line"></span><br><span class="line"><span class="comment"># 目录~/.config/netease-cloud-music和~/.cache/netease-cloud-music</span></span><br><span class="line"><span class="comment"># 分别为网易云音乐的配置和缓存文件</span></span><br><span class="line"><span class="comment"># 若不更改权限会造成网易云音乐无法自动登录以及设置丢失问题</span></span><br></pre></td></tr></tbody></table></figure><p><strong>正式步骤如下:</strong></p><p>1.同样是<a target="_blank" rel="noopener" href="https://music.163.com/#/download">官网</a>下载安装</p><p>2.在<code>~/</code>新建<code>.music.sh</code>脚本,内容如下:</p><figure class="highlight bash"><figcaption><span>文件位置:~/.music.sh</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="built_in">unset</span> SESSION_MANAGER && netease-cloud-music & <span class="comment">#后台运行网易云</span></span><br><span class="line"><span class="comment"># 如果觉得字体过小,可以更改第二行命令为如下命令</span></span><br><span class="line"><span class="comment"># unset SESSION_MANAGER && netease-cloud-music --force-device-scale-factor=1.5 & #后台运行网易云</span></span><br><span class="line"><span class="comment"># 1.5为缩放倍数,可自行看情况调整</span></span><br><span class="line"><span class="built_in">disown</span> <span class="comment">#使网易云音乐进程不会随终端关闭而结束</span></span><br><span class="line"><span class="built_in">exit</span> 0 <span class="comment">#自动关闭终端,若不想自动关闭终端可删除该行</span></span><br></pre></td></tr></tbody></table></figure><p>3.设置一个方便的命令别名,在<code>~/.bashrc</code>添加如下内容</p><figure class="highlight bash"><figcaption><span>文件位置:~/.bashrc</span></figcaption><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">alias</span> music=<span class="string">'. ~/.music.sh'</span></span><br><span class="line"><span class="comment"># 注意在“.”后有一个空格 </span></span><br><span class="line"><span class="comment"># 脚本名.music.sh和命令别名music可自行更换成其他名字</span></span><br></pre></td></tr></tbody></table></figure><p>4.重启计算机,或者在当前终端输入命令<code>source ~/.bashrc</code>使步骤3中的别名生效</p><p>5.输入命令 <code>music</code>就可以启动网易云音乐了。<strong>同时终端会自动关闭</strong></p><h3 id="tips">tips:</h3><p>对于步骤一的<code>. .music.sh</code>命令,第一个点是一种执行脚本的方式。Linux执行文件有如下几种方式:</p><ul><li><code>./xxx.sh</code>意思是在当前目录执行<code>xxx.sh</code>文件,一般来说会创建一个shell子进程来执行程序。</li><li><code>sh xxx.sh</code>意思是用shell解释器来执行xxx.sh脚本,与方法一不同的是不要求文件有可执行权限,其他相同。</li><li><code>. xxx.sh</code>(与<code>source xxx.sh</code>命令效果相同)意思是读入并执行脚本。与第一种相比,不同之处在于执行时是把脚本内命令一行一行读入当前终端来执行的,并没有创建子进程来执行脚本。<a target="_blank" rel="noopener" href="https://blog.csdn.net/timchen525/article/details/76407735">moredetails</a></li></ul><p>旧方法虽然可行但是有很大的风险,一是从<code>.music.sh</code>脚本可以直接看到你的管理员密码,二是给与了网易云过高的权限。(不过此方法为我的自用方案,使用很久并没有出现问题)</p><p>新方法则完美的实现了命令行启动,安全快捷。最后感谢大佬的方法</p><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/a3551736/article/details/80748469">原文地址</a>,不过原文也是我写的,哈哈。</p></body></html>]]></content>
<summary type="html"><html><head></head><body><p><strong>Ubuntu 18.04 个性化(持续更新)</strong></p>
<figure>
<img src="/posts/38710/1560660828546.png" alt="desktop">
<figcaption aria-hidden="true">desktop</figcaption>
</figure></body></html></summary>
<category term="ubuntu" scheme="http://ljmeng.site/categories/ubuntu/"/>
<category term="ubuntu" scheme="http://ljmeng.site/tags/ubuntu/"/>
<category term="网易云音乐" scheme="http://ljmeng.site/tags/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90/"/>
<category term="baidunetdisk" scheme="http://ljmeng.site/tags/baidunetdisk/"/>
</entry>
<entry>
<title>linux学习笔记第二篇之bash</title>
<link href="http://ljmeng.site/posts/60978/"/>
<id>http://ljmeng.site/posts/60978/</id>
<published>2019-02-04T08:47:25.000Z</published>
<updated>2019-02-04T08:47:25.000Z</updated>
<content type="html"><![CDATA[<html><head></head><body><h2 id="快捷键">快捷键</h2><ul><li><code>^u</code> 向前删除所有; <code>^k</code> 向后删除所有</li><li><code>^a</code>(ahead)移至最前面,<code>^e</code>(end)移至最后</li></ul><h2 id="变量">变量</h2><h3 id="内置变量例如pathhomerandom">内置变量例如<code>PATH</code>,<code>HOME</code>,<code>RANDOM</code></h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[dmtsai@study ~]$ <span class="built_in">declare</span> -i number=<span class="variable">$RANDOM</span>*10/32768 ; <span class="built_in">echo</span> <span class="variable">$number</span></span><br><span class="line">8 <== 此時會隨機取出 0~9 之間的數值喔!</span><br></pre></td></tr></tbody></table></figure><ul><li><p>获取环境变量<code>env</code>(所有bash都具有的变量).获取环境变量和自订变量<code>set</code></p></li><li><p>将临时变量变为环境变量<code>export var</code>,获取当前的环境变量<code>export</code></p><p></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">work=/home/s0me/tmp </span><br><span class="line"><span class="built_in">export</span> work <span class="comment">#当前bash和所有的子进程的环境变量,新的bash shell中并不会有此变量</span></span><br><span class="line"><span class="comment">#只能将某个变量设为子进程和当前进程的环境变量</span></span><br><span class="line"></span><br><span class="line">bash <span class="comment">#打开新的bash子进程</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$work</span> <span class="comment">#成功的进入了设定好的work目录</span></span><br><span class="line"><span class="built_in">exit</span> <span class="comment">#关闭子bash进程</span></span><br></pre></td></tr></tbody></table></figure><p></p></li></ul><span id="more"></span><h3 id="变量取用">变量取用</h3><p><code>$var</code> or <code>${var}</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="variable">$HOME</span> <span class="comment">#输出 /home/dream</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">${HOME}</span> <span class="comment">#输出同上</span></span><br></pre></td></tr></tbody></table></figure><h3 id="变量设定规则">变量设定规则</h3><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">######变量后的注释行均为执行 echo ${变量} 之后的输出 ######</span></span><br><span class="line">myn=s0me <span class="comment">#正确</span></span><br><span class="line"><span class="comment">#s0me</span></span><br><span class="line">myname2=s0me2 <span class="comment">#正确</span></span><br><span class="line"><span class="comment">#s0me2</span></span><br><span class="line">var=<span class="string">"lang is <span class="variable">$LANG</span>"</span> <span class="comment">#双引号内特殊字符保留原有特性</span></span><br><span class="line"><span class="comment">#lang is zh_CN.UTF-8</span></span><br><span class="line">var2=<span class="string">'lang is $LANG'</span> <span class="comment">#单引号全为一般字符</span></span><br><span class="line"><span class="comment">#lang is $LANG</span></span><br><span class="line">myname3=s0me\ meng <span class="comment">#正确 \ 可将特殊字符[enter],[$],[\],[space],[']变为一般字符</span></span><br><span class="line"><span class="comment">#s0me meng</span></span><br><span class="line">version=$(<span class="built_in">uname</span> -r) <span class="comment">#一串指令调用其他指令,可以用[`指令`]或者[$(指令)]</span></span><br><span class="line"><span class="comment">#4.15.0-44-generic</span></span><br><span class="line">myname4=<span class="variable">${myn}</span>12 <span class="comment">#扩增变量内容,直接在[${指令}]或者["$指令"]后连接即可</span></span><br><span class="line"><span class="comment">#s0me12</span></span><br><span class="line">myname5=<span class="variable">${myn}</span>:123\;<span class="string">"<span class="variable">$myn</span>"</span>233\;<span class="string">"<span class="variable">${myn}</span>"</span>2333 <span class="comment">#连接变量内容</span></span><br><span class="line"><span class="comment">#s0me:123;s0me233;s0me2333</span></span><br></pre></td></tr></tbody></table></figure><ul><li><code>=</code>连接,且等号两侧无空白字符</li><li>变量中有空白字符,可用引号将变数内容结合起来<ul><li><code>"</code>双引号保留特殊字符原有特性</li><li><code>'</code>单引号全为一般字符</li></ul></li><li><code>\</code>转义功能,注意可将<code>[sapce]转义</code>, 即<code>var=i\ am\ foo</code>是合法语句</li><li>一串指令调用其他指令,可以用 [`指令`] 或者[$(指令)]<strong>优先调用</strong></li><li>扩增变量内容,直接在<code>[${指令}]</code>或者<code>[" $指令"]</code>后连接即可</li><li><strong>特别注意:</strong>反单引号,<code>$(指令)</code>(小括号)只能包含指令;<code>${变量}</code>(中括号)只能包含变量</li><li>若该变量需要在其他子程序执行,则需要以export来使变量变成环境变量<code>export var</code></li><li>取消变量<code>unset</code></li></ul><h3 id="一些常用变量">一些常用变量</h3><ol type="1"><li><strong><code>PS1</code></strong>命令提示字元,即<code>s0me@s0me-Laptop:~$</code><ul><li><code>\d</code>:可显示出『星期月日』的日期格式,如:"Mon Feb2"</li><li><code>\H</code>:完整的主机名称。举例来说,鸟哥的练习机为『study.centos.vbird』</li><li><code>\h</code>:仅取主机名称在第一个小数点之前的名字,如鸟哥主机则为『study』后面省略</li><li><code>\t</code> :显示时间,为24 小时格式的『HH:MM:SS』</li><li><code>\T</code>:显示时间,为12 小时格式的『HH:MM:SS』</li><li><code>\A</code> :显示时间,为24 小时格式的『HH:MM』</li><li><code>\@</code> :显示时间,为12 小时格式的『am/pm』样式</li><li><code>\u</code>:目前使用者的帐号名称,如『dmtsai』;</li><li><code>\v</code>:BASH的版本资讯,如鸟哥的测试主机版本为4.2.46(1)-release,仅取『4.2』显示</li><li><code>\w</code>:完整的工作目录名称,由根目录写起的目录名称。但家目录会以~取代;</li><li><code>\W</code>:利用basename函数取得工作目录名称,所以仅会列出最后一个目录名。</li><li><code>\#</code>:下达的第几个指令。</li><li><code>\$</code> :提示字元,如果是root 时,提示字元为# ,否则就是$啰~</li></ul></li></ol><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#example 01</span></span><br><span class="line">[dmtsai@study ~]$ <span class="built_in">cd</span> /home </span><br><span class="line">[dmtsai@study home]$ PS1=<span class="string">'[\u@\h \w \A #\#]\$ '</span></span><br><span class="line">[dmtsai@study /home 17:02 <span class="comment">#85]$</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#example 02</span></span><br><span class="line">s0me@s0me-laptop:~$ PS1=<span class="string">'[Path:\w][\#]\$'</span></span><br><span class="line">[Path:~][2]$</span><br><span class="line"><span class="comment">#注意修改时用单引号,避免提前转义</span></span><br></pre></td></tr></tbody></table></figure><ol start="2" type="1"><li><p><code>$</code> 目前shell的进程号.</p><p><code>echo $$</code>,会返回目前shell的 pid</p></li><li><p><code>?</code>上一条指令的传回值<code>echo $?</code>为0,表示上一条指令执行成功,不为0,表示执行错误</p></li></ol><h3 id="设定语系">设定语系</h3><ul><li><p><code>locale -a</code> 显示当前支持的所有语言</p></li><li><p><code>locale</code>显示当前语言相关的环境变量,一般修改<code>LANG</code>即可</p><p></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[dmtsai@study ~]$ locale <==后面不加任何选项与参数即可!</span><br><span class="line">LANG=en_US <==主语言的环境 </span><br><span class="line">LC_CTYPE=<span class="string">"en_US"</span> <==字元(文字)辨识的编码 </span><br><span class="line">LC_NUMERIC=<span class="string">"en_US"</span> <==数字系统的显示讯息 </span><br><span class="line">LC_TIME=<span class="string">"en_US"</span> <==时间系统的显示资料 </span><br><span class="line">LC_COLLATE=<span class="string">"en_US"</span> <==字串的比较与排序等 </span><br><span class="line">LC_MONETARY=<span class="string">"en_US"</span> <==币值格式的显示等 </span><br><span class="line">LC_MESSAGES=<span class="string">"en_US"</span> <==讯息显示的内容,如功能表、错误讯息等 </span><br><span class="line">LC_ALL= <==整体语系的环境</span><br></pre></td></tr></tbody></table></figure><p></p></li><li><p>如果不生效可用<code>export</code>进行一下转换</p></li></ul><h2 id="读取键盘输入">读取键盘输入</h2><p>命令 <code>read</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">read</span> [-pt] var</span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -p :后面可以接提示字元!</span></span><br><span class="line"><span class="comment"># -t :后面可以接等待的『秒数!』这个比较有趣~不会一直等待使用者啦!</span></span><br><span class="line">$ <span class="built_in">read</span> -p <span class="string">"your name?"</span> -t 4 name</span><br><span class="line">your name?ljmeng</span><br><span class="line">$ <span class="built_in">echo</span> <span class="variable">${name}</span></span><br><span class="line">ljmeng</span><br></pre></td></tr></tbody></table></figure><h2 id="变量类型声明">变量类型声明</h2><p>命令<code>declare</code></p><p>变量类型预设为字符串</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">declare</span> [-aixr] variable </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -a :将后面名为variable 的变数定义成为阵列(array) 类型</span></span><br><span class="line"><span class="comment"># -i :将后面名为variable 的变数定义成为整数数字(integer) 类型</span></span><br><span class="line"><span class="comment"># -x :用法与export 一样,就是将后面的variable 变成环境变数;</span></span><br><span class="line"><span class="comment"># -r :将变数设定成为readonly 类型,该变数不可被更改内容,也不能unset</span></span><br></pre></td></tr></tbody></table></figure><h2 id="数组array变量类型">数组(array)变量类型</h2><p>设定方法 <code>var[index]=content</code> , <span class="math inline">\(index \in [0, +\infin)\)</span>.</p><h2 id="限制可用资源">限制可用资源</h2><p>命令 <code>ulimit [-SHacdfltu] [配额]</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[dmtsai@study ~]$ <span class="built_in">ulimit</span> [-SHacdfltu] [配额] </span><br><span class="line"><span class="comment"># 选项与参数: </span></span><br><span class="line"><span class="comment"># -H :hard limit ,严格的设定,必定不能超过这个设定的数值; </span></span><br><span class="line"><span class="comment"># -S :soft limit ,警告的设定,可以超过这个设定值,但是若超过则有警告讯息。 </span></span><br><span class="line"><span class="comment"># 在设定上,通常soft 会比hard 小,举例来说,soft 可设定为80 而hard </span></span><br><span class="line"><span class="comment"># 设定为100,那么你可以使用到90 (因为没有超过100),但介于80~100 之间时, </span></span><br><span class="line"><span class="comment"># 系统会有警告讯息通知你! </span></span><br><span class="line"><span class="comment"># -a :后面不接任何选项与参数,可列出所有的限制额度; </span></span><br><span class="line"><span class="comment"># -c :当某些程式发生错误时,系统可能会将该程式在记忆体中的资讯写成档案(除错用), </span></span><br><span class="line"><span class="comment"># 这种档案就被称为核心档案(core file)。此为限制每个核心档案的最大容量。 </span></span><br><span class="line"><span class="comment"># -f :此shell 可以建立的最大档案容量(一般可能设定为2GB)单位为Kbytes </span></span><br><span class="line"><span class="comment"># -d :程序可使用的最大断裂记忆体(segment)容量; </span></span><br><span class="line"><span class="comment"># -l :可用于锁定(lock) 的记忆体量 </span></span><br><span class="line"><span class="comment"># -t :可使用的最大CPU 时间(单位为秒) </span></span><br><span class="line"><span class="comment"># -u :单一使用者可以使用的最大程序(process)数量。</span></span><br></pre></td></tr></tbody></table></figure><h2 id="变量内容的删除取代与替换optimal">变量内容的删除,取代与替换(optimal)</h2><h3 id="删除与取代">删除与取代</h3><p><span id="inline-blue">注意删除内容一定从某一端开始并包含某一端</span>,不能单独删除中间一段</p><ul><li><code>#</code> 从开始删除 第一个<strong>最短符合通配符的</strong></li><li><code>##</code> 从开始删除 第一个<strong>最长符合通配符的</strong></li><li><code>%</code> 从结尾开始 第一个<strong>最短符合通配符的</strong></li><li><code>%%</code> 从结尾开始 第一个<strong>最长符合通配符的</strong></li></ul><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH}</span></span><br><span class="line"><span class="comment"># /usr/local/sbin:/usr/local/bin:/bin:/usr/games:/usr/local/games:/snap/bin</span></span><br><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH#/*:}</span></span><br><span class="line"><span class="comment"># /usr/local/bin:/bin:/usr/games:/usr/local/games:/snap/bin</span></span><br><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH##/*:}</span></span><br><span class="line"><span class="comment"># /snap/bin</span></span><br><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH%/*bin}</span></span><br><span class="line"><span class="comment"># /usr/local/sbin:/usr/local/bin:/bin:/usr/games:/usr/local/games:/snap</span></span><br><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH%%/*bin}</span></span><br><span class="line"><span class="comment"># <==注意这里输出为空</span></span><br><span class="line">s0me@s0mE-laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH%%/*:}</span> <span class="comment">#为无效命令,因为不包含右端</span></span><br><span class="line"><span class="comment"># /usr/local/sbin:/usr/local/bin:/bin:/usr/games:/usr/local/games:/snap/bin</span></span><br></pre></td></tr></tbody></table></figure><ul><li><code>${var/old_str/new_str}</code>替换第一个符合旧字串的字符串</li><li><code>${var//old_str/new_str}</code> 替换全部符合旧字串的字符串</li></ul><h3 id="变量的测试与内容替换">变量的测试与内容替换</h3><ul><li>判断变量是否存在(即是否初始化过)或者是否为空字符串</li></ul><table><colgroup><col style="width: 23%"><col style="width: 24%"><col style="width: 24%"><col style="width: 27%"></colgroup><thead><tr class="header"><th>变数设定方式</th><th>str 没有设定</th><th>str 为空字串</th><th>str 已设定非为空字串</th></tr></thead><tbody><tr class="odd"><td>var=${str-expr}</td><td>var=expr</td><td>var=</td><td>var=$str</td></tr><tr class="even"><td>var=${str:-expr}</td><td>var=expr</td><td>var=expr</td><td>var=$str</td></tr><tr class="odd"><td>var=${str+expr}</td><td>var=</td><td>var=expr</td><td>var=expr</td></tr><tr class="even"><td>var=${str:+expr}</td><td>var=</td><td>var=</td><td>var=expr</td></tr><tr class="odd"><td>var=${str=expr}</td><td>str=expr var=expr</td><td>str不变 var=</td><td>str不变 var=$str</td></tr><tr class="even"><td>var=${str:=expr}</td><td>str=expr var=expr</td><td>str=expr var=expr</td><td>str不变 var=$str</td></tr><tr class="odd"><td>var=${str?expr}</td><td>expr 输出至stderr</td><td>var=</td><td>var=$str</td></tr><tr class="even"><td>var=${str:?expr}</td><td>expr 输出至stderr</td><td>expr 输出至stderr</td><td>var=$str</td></tr></tbody></table><h2 id="命令别名与历史命令">命令别名与历史命令</h2><ol type="1"><li>命令别名<code>alias</code>,<code>unalias</code></li><li>历史命令<code>history</code>,<code>history 5</code>可以查询最近五次的命令</li><li><code>!n</code>执行第n次命令</li><li><code>!!</code>执行上一次命令</li><li><code>!al</code> 执行最近的以<code>al</code>开头的那个指令</li></ol><h2 id="shell-的操作环境">Shell 的操作环境</h2><h3 id="路径与指令搜索顺序">路径与指令搜索顺序</h3><ol type="1"><li>相对路径</li><li>alias寻找</li><li>bash内置指令寻找</li><li>通过$PATH变量查找</li></ol><h3 id="bash的进站与欢迎讯息">bash的进站与欢迎讯息</h3><ol type="1"><li><p>终端进站提示信息<code>cat /etc/issue</code></p><ul><li><p>内部代码含义</p><p></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">\d本地端时间的日期;</span><br><span class="line">\l显示第几个终端机介面;</span><br><span class="line">\m显示硬体的等(i386/i486/i586/i686...);</span><br><span class="line">\n显示主机的网路名称;</span><br><span class="line">\O显示domain name;</span><br><span class="line">\r作业系统的版本(相当于uname -r) </span><br><span class="line">\t显示本地端时间的时间;</span><br><span class="line">\S作业系统的名称;</span><br><span class="line">\v作业系统的版本。</span><br></pre></td></tr></tbody></table></figure><p></p></li></ul></li><li><p><code>/etc/issue.net</code> 提供给telnet连接</p></li><li><p><code>/etc/motd</code>你编写的给所有登陆者的信息</p></li></ol><h3 id="bash的环境设定档">bash的环境设定档</h3><p>login 与 non-login shell</p><h4 id="login-shell">login shell</h4><p>1.<code>etc/profile</code>包含环境变量,呼叫如下文档:</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/etc/profile.d/*.sh <span class="comment">#包含命令别名</span></span><br><span class="line">/etc/locale.conf <span class="comment">#语系设定</span></span><br><span class="line">/usr/share/bash-completion/completions/* <span class="comment">#命令tab自动补全处理</span></span><br></pre></td></tr></tbody></table></figure><p>2.<code>~/.bash_profile</code> or<code>~/.bash_login</code> or<code>~/.profile</code>,包含用户个人设定,会呼叫<code>~/.bashrc</code></p><h4 id="non-login-shell">non-login shell</h4><p>只会读取<code>~/.bashrc</code></p><h4 id="source-命令">source 命令</h4><p><code>source xxx</code> or <code>. xxx</code>,读入文档<code>xxx</code>的设定, 无需重启系统,即可使自己的修改生效</p><h4 id="其他设定文档">其他设定文档</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/etc/man_db.conf <span class="comment"># man page 查找路径</span></span><br><span class="line">~/.bash_history <span class="comment">#历史命令</span></span><br><span class="line">~/.bash_logout <span class="comment"># bash登出时运行的命令</span></span><br></pre></td></tr></tbody></table></figure><h3 id="终端机tty的环境设定-stty-set">终端机(tty)的环境设定: stty,set</h3><h4 id="stty">stty</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">stty</span> [-a] </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -a :将目前所有的stty 参数列出来;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 列出所有按键与按键内容</span></span><br><span class="line">$ <span class="built_in">stty</span> -a</span><br><span class="line">speed 38400 baud; rows 20; columns 90; line = 0;</span><br><span class="line">intr = ^C ; quit = ^\; erase = ^? ; <span class="built_in">kill</span> = ^U; eof = ^D ; eol = <undef>; eol2 = <undef>;</span><br><span class="line">swtch = <undef>; start = ^Q ; stop = ^S ; susp = ^Z ; rprnt = ^R; werase = ^W; lnext = ^V;</span><br><span class="line">flush = ^O; min = 1; time = 0;</span><br></pre></td></tr></tbody></table></figure><p><span id="inline-blue">常用按键对照表如下</span></p><table><colgroup><col style="width: 5%"><col style="width: 35%"><col style="width: 59%"></colgroup><thead><tr class="header"><th>变量</th><th>快捷键</th><th>含义</th></tr></thead><tbody><tr class="odd"><td>intr</td><td>【ctrl+c】【^c】</td><td>发送一个interrupt (中断) 的讯号给目前正在run的程序</td></tr><tr class="even"><td>quit</td><td>【ctrl+】【^】</td><td>发送一个quit 的讯号给目前正在run的程序</td></tr><tr class="odd"><td>erase</td><td>【ctrl+?】【^?】【backsapce键】</td><td>删除字符(删除键用^?表示,很有意思)</td></tr><tr class="even"><td>kill</td><td>【ctrl+u】【^u】</td><td>删除在目前指令列上光标前的所有文字</td></tr><tr class="odd"><td>eof</td><td>【ctrl+d】【^d】</td><td>End of file 的意思,代表『结束输入』</td></tr><tr class="even"><td>start</td><td>【ctrl+q】【^q】</td><td>在某个程序停止后,重新启动他的output</td></tr><tr class="odd"><td>stop</td><td>【ctrl+s】【^s】</td><td>停止目前屏幕的输出(程序仍然在运行)</td></tr><tr class="even"><td>susp</td><td>【ctrl+z】【^z】</td><td>送出一个terminal stop(终端停止)的讯号给正在run的程序</td></tr></tbody></table><p>修改设定方法</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">stty</span> erase ^h <span class="comment">#这个设定看看就好,不必真的实做!不然还要改回来!</span></span><br></pre></td></tr></tbody></table></figure><h4 id="set">set</h4><p><code>-</code>启用相应设定,<code>+</code>取消相应设定</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">set</span> [-uvCHhmBx] </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -u :预设不启用。若启用后,当使用未设定变数时,会显示错误讯息;</span></span><br><span class="line"><span class="comment"># -v :预设不启用。若启用后,在讯息被输出前,会先显示讯息的原始内容;</span></span><br><span class="line"><span class="comment"># -x :预设不启用。若启用后,在指令被执行前,会显示指令内容(前面有++ 符号)</span></span><br><span class="line"><span class="comment"># -h :预设启用。与历史命令有关;</span></span><br><span class="line"><span class="comment"># -H :预设启用。与历史命令有关;</span></span><br><span class="line"><span class="comment"># -m :预设启用。与工作管理有关;</span></span><br><span class="line"><span class="comment"># -B :预设启用。与刮号[] 的作用有关;</span></span><br><span class="line"><span class="comment"># -C :预设不启用。若使用> 等,则若档案存在时,该档案不会被覆盖。</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 范例一:显示目前所有的set设定值 </span></span><br><span class="line">$ <span class="built_in">echo</span> $-</span><br><span class="line"><span class="comment"># himBH</span></span><br><span class="line"><span class="comment"># 那个$- 变数内容就是set 的所有设定啦!bash 预设是himBH 喔!</span></span><br><span class="line"></span><br><span class="line">范例二:设定<span class="string">"若使用未定义变数时,则显示错误讯息"</span> </span><br><span class="line">$ <span class="built_in">set</span> -u </span><br><span class="line">$ <span class="built_in">echo</span> <span class="variable">$vbirding</span></span><br><span class="line"><span class="comment"># -bash: vbirding: unbound variable</span></span><br><span class="line"><span class="comment"># 预设情况下,未设定/未宣告的变数都会是『空的』,不过,若设定-u 参数,</span></span><br><span class="line"><span class="comment"># 那么当使用未设定的变数时,就会有问题啦!很多的shell 都预设启用-u 参数。</span></span><br><span class="line"><span class="comment"># 若要取消这个参数,输入set +u 即可!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 范例三:执行前,显示该指令内容。</span></span><br><span class="line">$ <span class="built_in">set</span> -x </span><br><span class="line"><span class="comment"># ++ printf '\033]0;%s@%s:%s\007' dmtsai study '~' #这个是在列出提示字元的控制码!</span></span><br><span class="line">$ <span class="built_in">echo</span> <span class="variable">${HOME}</span></span><br><span class="line"><span class="comment"># + echo /home/dmtsai</span></span><br><span class="line"><span class="comment"># /home/dmtsai</span></span><br><span class="line"><span class="comment"># ++ printf '\033]0;%s@%s:%s\007' dmtsai study '~'</span></span><br><span class="line"><span class="comment"># 看见否?要输出的指令都会先被列印到萤幕上喔!前面会多出+ 的符号!</span></span><br></pre></td></tr></tbody></table></figure><h3 id="万用字符和特殊符号">万用字符和特殊符号</h3><p>万用字符</p><table><colgroup><col style="width: 7%"><col style="width: 92%"></colgroup><thead><tr class="header"><th>符号</th><th>意义</th></tr></thead><tbody><tr class="odd"><td>*</td><td>『 0 个到无穷多个』任意字元</td></tr><tr class="even"><td>?</td><td>『一定有一个』任意字元</td></tr><tr class="odd"><td>[ ]</td><td>『一定有一个在括号内』的字元(非任意字元)。[abcd]代表『一定有一个字元,可能是a, b, c, d 这四个任何一个』</td></tr><tr class="even"><td>[ - ]</td><td>若有减号在中括号内时,代表『在编码顺序内的所有字元』。例如[0-9] 代表0 到9 之间的所有数字</td></tr><tr class="odd"><td>[^ ]</td><td>若中括号内的第一个字元为指数符号(^),那表示『反向选择』,例如·<code>[^abc]</code>代表一定有一个字元,只要是非a, b, c 的其他字元就接受的意思。</td></tr></tbody></table><p>特殊符号</p><table><colgroup><col style="width: 7%"><col style="width: 92%"></colgroup><thead><tr class="header"><th>符号</th><th>内容</th></tr></thead><tbody><tr class="odd"><td>#</td><td>注解符号:这个最常被使用在script当中,视为说明!在后的资料均不执行</td></tr><tr class="even"><td>\</td><td>跳脱符号:将『特殊字元或万用字元』还原成一般字元</td></tr><tr class="odd"><td>|</td><td>管线(pipe):分隔两个管线命令的界定(后两节介绍);</td></tr><tr class="even"><td>;</td><td>连续指令下达分隔符号:连续性命令的界定(注意!与管线命令并不相同)</td></tr><tr class="odd"><td>~</td><td>使用者的家目录</td></tr><tr class="even"><td>$</td><td>取用变数前置字元:亦即是变数之前需要加的变数取代值</td></tr><tr class="odd"><td>&</td><td>工作控制(job control):将指令变成背景下工作</td></tr><tr class="even"><td>!</td><td>逻辑运算意义上的『非』 not 的意思!</td></tr><tr class="odd"><td>/</td><td>目录符号:路径分隔的符号</td></tr><tr class="even"><td>>, >></td><td>资料流重导向:输出导向,分别是『取代』与『累加』</td></tr><tr class="odd"><td><, <<</td><td>资料流重导向:输入导向(这两个留待下节介绍)</td></tr><tr class="even"><td>' '</td><td>单引号,不具有变数置换的功能($ 变为纯文字)</td></tr><tr class="odd"><td>" "</td><td>具有变数置换的功能!($ 可保留相关功能)</td></tr><tr class="even"><td>` `</td><td>两个『 ` 』中间为可以先执行的指令,亦可使用$( )</td></tr><tr class="odd"><td>( )</td><td>在中间为子shell 的起始与结束</td></tr><tr class="even"><td>{ }</td><td>在中间为命令区块的组合!</td></tr></tbody></table><h2 id="数据流重定向">数据流重定向</h2><h3 id="重定向简介">重定向简介</h3><h4 id="三种数据流-stdout-stdin-stderr">三种数据流 <code>stdout</code>,<code>stdin</code>, <code>stderr</code></h4><figure><img src="/posts/60978/centos7_redirection.jpg" alt="指令执行过程的资料传输情况"><figcaption aria-hidden="true">指令执行过程的资料传输情况</figcaption></figure><table><thead><tr class="header"><th>类型</th><th>代码</th><th>符号</th></tr></thead><tbody><tr class="odd"><td>标准输入(stdin)</td><td>0</td><td>< 或<<</td></tr><tr class="even"><td>标准输出(stdout)</td><td>1</td><td>> 或>>; 1>或1>>也可</td></tr><tr class="odd"><td>标准错误输出(stderr)</td><td>2</td><td>2> 或2>></td></tr></tbody></table><p>单个>表示以覆盖方式输出,两个>>表示以追加的方式输出</p><p>单个<表示以后面的文件为标准输入,两个<<后面表示自己定义的输入结束标志符</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment"># 范例二:利用一般身份帐号搜寻/home底下是否有名为.bashrc的档案存在 </span></span><br><span class="line">$ find /home -name .bashrc <==身份是dmtsai喔!</span><br><span class="line"><span class="comment"># find: '/home/arod': Permission denied <== Standard error output </span></span><br><span class="line"><span class="comment"># find: '/home/alex': Permission denied <== Standard error output </span></span><br><span class="line"><span class="comment"># /home/dmtsai/.bashrc <== Standard output</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 范例三:承范例二,将stdout与stderr分存到不同的档案去 </span></span><br><span class="line">$ find /home -name .bashrc > list_right 2> list_error</span><br><span class="line"><span class="comment">#此时屏幕中无任何信息,输出全部 重定向到了相应文件中</span></span><br></pre></td></tr></tbody></table></figure><h4 id="devnull垃圾桶黑洞"><code>dev/null</code>垃圾桶黑洞</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 范例四:承范例三,将错误的资料丢弃,萤幕上显示正确的资料 </span></span><br><span class="line">$ find /home -name .bashrc 2> /dev/null </span><br><span class="line"><span class="comment"># /home/dmtsai/.bashrc <==只有stdout会显示到萤幕上, stderr被丢弃了</span></span><br></pre></td></tr></tbody></table></figure><h4 id="将正确与错误输出写入同一个文件">将正确与错误输出写入同一个文件</h4><p><code>2>&1</code>将2号输出流重定向至1号输出流,<code>1>&2</code>同理</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment"># 范例五:将指令的资料全部写入名为list的档案中 </span></span><br><span class="line">$ find /home -name .bashrc > list 2> list <span class="comment"># <==错误 </span></span><br><span class="line">$ find /home - name .bashrc > list 2>&1 <span class="comment"># <==正确 </span></span><br><span class="line">$ find /home -name .bashrc &> list <span class="comment"># <==正确</span></span><br></pre></td></tr></tbody></table></figure><h4 id="stdin-与">stdin < 与 <<</h4><p>cat 创建文档 <code>cat > catfile</code></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 利用cat指令来建立一个档案的简单流程 </span></span><br><span class="line">$ <span class="built_in">cat</span> > catfile </span><br><span class="line">testing</span><br><span class="line"><span class="built_in">cat</span> file <span class="built_in">test</span> </span><br><span class="line"><span class="comment"># <==这里按下[ctrl]+d来离开</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 用stdin取代键盘的输入以建立新档案的简单流程 </span></span><br><span class="line">$ <span class="built_in">cat</span> > catfile < ~/.bashrc </span><br><span class="line"></span><br><span class="line"><span class="comment"># 用关键字结束输入而不是^d</span></span><br><span class="line">$ <span class="built_in">cat</span> > catfile << <span class="string">"eof"</span> </span><br><span class="line">> This is a <span class="built_in">test</span>. </span><br><span class="line">> OK now stop </span><br><span class="line">> eof <span class="comment"># <==输入这关键字,立刻就结束而不需要输入[ctrl]+d,文件最终不包含“eof”</span></span><br></pre></td></tr></tbody></table></figure><h3 id="命令执行判断依据">命令执行判断依据: ;, &&, ||</h3><h4 id="cmd-cmd">cmd ; cmd</h4><p>不考虑指令相关性的连续指令下达</p><h4 id="指令回传值-与-或">$? (指令回传值) 与&& 或||</h4><p>单独指令含义如下</p><table><colgroup><col style="width: 18%"><col style="width: 81%"></colgroup><thead><tr class="header"><th>指令下达情况</th><th>说明</th></tr></thead><tbody><tr class="odd"><td>cmd1 && cmd2</td><td>cmd1执行完毕后, 若正确执行($? == 0),则执行cmd2。否则不执行。</td></tr><tr class="even"><td>cmd1 || cmd2</td><td>cmd1执行完毕后, 若未正确执行($? != 0),则cmd2执行。否则不执行。</td></tr></tbody></table><p>不同的连接顺序含义不同</p><table><colgroup><col style="width: 81%"><col style="width: 18%"></colgroup><thead><tr class="header"><th>指令</th><th>含义</th></tr></thead><tbody><tr class="odd"><td>cmd1 && cmd2 || cmd3</td><td>如果cmd1正确运行则执行cmd2,否则执行cmd3</td></tr><tr class="even"><td>cmd1 || cmd2 && cmd3</td><td>如果cmd1错误运行则执行cmd2,并执行cmd3,否则执行cmd3</td></tr></tbody></table><p>ps: 以上前提是cmd2,cmd3一旦执行都能正常运行</p><h2 id="管线命令pipe">管线命令(pipe)</h2><p>一般仅能处理<code>stdout</code>,会忽略<code>stderr</code>,不过可以通过<code>2>&1</code>处理<code>stderr</code></p><h3 id="撷取命令-cut-grep">撷取命令: cut, grep</h3><h4 id="cut">cut</h4><p>分解同一行的信息</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cut</span> -d <span class="string">'分隔字元'</span> -f fields <span class="comment"># <==用于有特定分隔字元 </span></span><br><span class="line">$ <span class="built_in">cut</span> -c 字元区间 <span class="comment"># <==用于排列整齐的讯息</span></span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -d :后面接分隔字元。与-f 一起使用;</span></span><br><span class="line"><span class="comment"># -f :依据-d 的分隔字元将一段讯息分割成为数段,用-f 取出第几段的意思;</span></span><br><span class="line"><span class="comment"># -c :以字元(characters) 的单位取出固定字元区间;</span></span><br><span class="line"></span><br><span class="line">dream@dream-Laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH}</span></span><br><span class="line"><span class="comment"># /home/dream/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin</span></span><br><span class="line">dream@dream-Laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH}</span> | <span class="built_in">cut</span> -d <span class="string">":"</span> -f 1,4,5-7</span><br><span class="line"><span class="comment"># /home/dream/miniconda3/bin:/usr/sbin:/usr/bin:/sbin:/bin</span></span><br><span class="line">dream@dream-Laptop:~$ <span class="built_in">echo</span> <span class="variable">${PATH}</span> | <span class="built_in">cut</span> -c 1,4,5-7</span><br><span class="line"><span class="comment"># /me/d</span></span><br></pre></td></tr></tbody></table></figure><h4 id="grep">grep</h4><p>分析一行信息,如果包含我们想要的信息,则取出该行。</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ grep [-acinv] [--color=auto] <span class="string">'搜寻字串'</span> filename </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -a :将binary 档案以text 档案的方式搜寻资料</span></span><br><span class="line"><span class="comment"># -c :计算找到'搜寻字串' 的次数(行数)</span></span><br><span class="line"><span class="comment"># -i :忽略大小写的不同,所以大小写视为相同</span></span><br><span class="line"><span class="comment"># -n :顺便输出行号</span></span><br><span class="line"><span class="comment"># -v :反向选择,亦即显示出没有'搜寻字串' 内容的那一行!</span></span><br><span class="line"><span class="comment"># --color=auto :可以将找到的关键字部分加上颜色的显示喔!</span></span><br></pre></td></tr></tbody></table></figure><h3 id="排序命令sort-wc-uniq">排序命令:sort, wc, uniq</h3><h4 id="sort">sort</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">sort</span> [-fbMnrtuk] [file or stdin] </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -f :忽略大小写的差异,例如A 与a 视为编码相同;</span></span><br><span class="line"><span class="comment"># -b :忽略最前面的空白字元部分;</span></span><br><span class="line"><span class="comment"># -M :以月份的名字来排序,例如JAN, DEC 等等的排序方法;</span></span><br><span class="line"><span class="comment"># -n :使用『纯数字』进行排序(预设是以文字型态来排序的);</span></span><br><span class="line"><span class="comment"># -r :反向排序;</span></span><br><span class="line"><span class="comment"># -u :就是uniq ,相同的资料中,仅出现一行代表;</span></span><br><span class="line"><span class="comment"># -t :分隔符号,预设是用[tab] 键来分隔;</span></span><br><span class="line"><span class="comment"># -k :以那个区间(field) 来进行排序的意思</span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h4 id="uniq">uniq</h4><p>重复的资料仅列出一个显示</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">uniq</span> [-ic]</span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -i :忽略大小写字元的不同;</span></span><br><span class="line"><span class="comment"># -c :进行计数</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#last将帐号列出,仅取出帐号栏,进行排序后仅取出一位</span></span><br><span class="line"><span class="variable">$last</span> | <span class="built_in">cut</span> -d <span class="string">' '</span> -f1 | <span class="built_in">sort</span> | <span class="built_in">uniq</span> -c</span><br></pre></td></tr></tbody></table></figure><h4 id="wc">wc</h4><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">wc</span> [-lwm] </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># 默认列出 『行、字数、字元数』</span></span><br><span class="line"><span class="comment"># -l :仅列出行;</span></span><br><span class="line"><span class="comment"># -w :仅列出多少字(英文单字);</span></span><br><span class="line"><span class="comment"># -m :多少字元;</span></span><br></pre></td></tr></tbody></table></figure><h3 id="双向重导向-tee">双向重导向 tee</h3><figure><img src="/posts/60978/0320bash_5.png" alt="tee 的工作流程示意图"><figcaption aria-hidden="true">tee 的工作流程示意图</figcaption></figure><p>tee功能如图所示,tee输出到screen其实就是 stdout.</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">tee</span> [-a] file</span><br><span class="line"><span class="comment"># -a : 以append的方式加入到资料file中</span></span><br><span class="line"></span><br><span class="line">$ last | <span class="built_in">tee</span> last.list | <span class="built_in">cut</span> -d <span class="string">" "</span> -f1 </span><br><span class="line"><span class="comment"># 导出到last.list并且下一步还有处理并最终会输出到屏幕上</span></span><br></pre></td></tr></tbody></table></figure><h3 id="字元转换命令-tr-col-join-paste-expand">字元转换命令 tr, col,join, paste, expand</h3><h4 id="tr">tr</h4><p>tr 可以用来删除一段讯息当中的文字,或者是进行文字讯息的替换!</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">tr</span> [-ds] SET1 ... </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -d :删除讯息当中的SET1 这个字串;</span></span><br><span class="line"><span class="comment"># -s :取代掉重复的字元!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 将last输出的讯息中,所有的小写变成大写字元</span></span><br><span class="line">$ last | <span class="built_in">tr</span> <span class="string">'[a-z]'</span> <span class="string">'[A-Z]'</span> </span><br></pre></td></tr></tbody></table></figure><h4 id="col">col</h4><p>将[tab] 按键取代成为空白键</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ col [-xb] </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -x :将tab 键转换成对等的空白键</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 利用cat -A显示出所有特殊按键,最后以col将[tab]转成空白 </span></span><br><span class="line">$ <span class="built_in">cat</span> -A /etc/man_db.conf <span class="comment"># <==此时会看到很多^I的符号,那就是tab </span></span><br><span class="line">$ <span class="built_in">cat</span> /etc/man_db.conf | col -x | <span class="built_in">cat</span> -A | more </span><br></pre></td></tr></tbody></table></figure><h4 id="join">join</h4><p>对比两个档案,将有<strong>"相同资料"</strong> 的行对应合并为一行,注意先排序,否则会少合并</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">join</span> [-ti12] file1 file2 </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -t :join 预设以空白字元分隔资料,并且比对『第一个栏位』的资料,</span></span><br><span class="line"><span class="comment"># 如果两个档案相同,则将两笔资料联成一行,且第一个栏位放在第一个!</span></span><br><span class="line"><span class="comment"># -i :忽略大小写的差异;</span></span><br><span class="line"><span class="comment"># -1 :这个是数字的1 ,代表『第一个档案要用那个栏位来分析』的意思;</span></span><br><span class="line"><span class="comment"># -2 :代表『第二个档案要用那个栏位来分析』的意思。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#例子如下</span></span><br><span class="line">$ <span class="built_in">join</span> -t <span class="string">':'</span> -1 4 /etc/passwd -2 3 /etc/group 2>/dev/null | <span class="built_in">head</span> -n 3 </span><br><span class="line"><span class="comment"># 0:root:x:0:root:/root:/bin/bash:root:x:</span></span><br><span class="line"><span class="comment"># 1:daemon:x:1:daemon:/usr/sbin:/usr/sbin/nologin:daemon:x:</span></span><br><span class="line"><span class="comment"># 2:bin:x:2:bin:/bin:/usr/sbin/nologin:bin:x:</span></span><br><span class="line">$ <span class="built_in">head</span> -n 3 /etc/passwd /etc/group</span><br><span class="line"><span class="comment"># ==> /etc/passwd <==</span></span><br><span class="line"><span class="comment"># root:x:0:0:root:/root:/bin/bash</span></span><br><span class="line"><span class="comment"># daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin</span></span><br><span class="line"><span class="comment"># bin:x:2:2:bin:/bin:/usr/sbin/nologin</span></span><br><span class="line"><span class="comment"># </span></span><br><span class="line"><span class="comment"># ==> /etc/group <==</span></span><br><span class="line"><span class="comment"># root:x:0:</span></span><br><span class="line"><span class="comment"># daemon:x:1:</span></span><br><span class="line"><span class="comment"># bin:x:2:</span></span><br></pre></td></tr></tbody></table></figure><h4 id="paste">paste</h4><p>将两行贴在一起,且中间以[tab]键隔开</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">paste</span> [-d] file1 file2 </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -d :后面可以接分隔字元。预设是以[tab] 来分隔的!</span></span><br><span class="line"><span class="comment"># - :如果file 部分写成- ,表示来自standard input 的资料的意思。</span></span><br></pre></td></tr></tbody></table></figure><h4 id="expand">expand</h4><p>将[tab] 按键转成空白键</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">expand</span> [-t] file </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -t :后面可以接数字。一般来说,一个tab 按键可以用8 个空白键取代。</span></span><br><span class="line"><span class="comment"># 我们也可以自行定义一个[tab] 按键代表多少个字元呢!</span></span><br></pre></td></tr></tbody></table></figure><h3 id="分割命令split">分割命令:split</h3><p>将大档案分割成小档案</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">split</span> [-bl] file PREFIX </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -b :后面可接欲分割成的档案大小,可加单位,例如b, k, m 等;</span></span><br><span class="line"><span class="comment"># -l :以行数来进行分割。</span></span><br><span class="line"><span class="comment"># PREFIX :代表前置字元的意思,可作为分割档案的前导文字。</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 分解例子</span></span><br><span class="line">$ <span class="built_in">split</span> -l 1 welcome.txt part</span><br><span class="line">$ ll</span><br><span class="line"><span class="comment"># 总用量 695</span></span><br><span class="line"><span class="comment"># ...</span></span><br><span class="line"><span class="comment"># -rwxrwxrwx 1 root root 1 3月 9 19:02 partaa*</span></span><br><span class="line"><span class="comment"># -rwxrwxrwx 1 root root 11 3月 9 19:02 partab*</span></span><br><span class="line"><span class="comment"># -rwxrwxrwx 1 root root 27 3月 9 19:02 partac*</span></span><br><span class="line"><span class="comment"># -rwxrwxrwx 1 root root 33 3月 9 19:02 partad*</span></span><br><span class="line"><span class="comment"># ...</span></span><br><span class="line"><span class="comment"># -rwxrwxrwx 1 root root 72 1月 31 13:06 welcome.txt*</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 合并方法</span></span><br><span class="line">$ <span class="built_in">cat</span> part* >> welcomeback</span><br></pre></td></tr></tbody></table></figure><h3 id="参数代换xargs">参数代换:xargs</h3><p>产生某个指令的参数,xargs可以读入stdin的资料,并且以空白字元或断行字元作为分辨,将stdin的资料分隔成为arguments 。</p><p>很多指令其实并不支援管线命令,因此我们可以透过xargs来提供该指令引用standardinput之用</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">$ xargs [-0epn] <span class="built_in">command</span> </span><br><span class="line"><span class="comment"># 选项与参数:</span></span><br><span class="line"><span class="comment"># -0 :如果输入的stdin 含有特殊字元,例如`, \, 空白键等等字元时,这个-0 参数</span></span><br><span class="line"><span class="comment"># 可以将他还原成一般字元。这个参数可以用于特殊状态喔!</span></span><br><span class="line"><span class="comment"># -e :这个是EOF (end of file) 的意思。后面可以接一个字串,当xargs 分析到这个字串时,</span></span><br><span class="line"><span class="comment"># 就会停止继续工作!</span></span><br><span class="line"><span class="comment"># -p :在执行每个指令的argument 时,都会询问使用者的意思;</span></span><br><span class="line"><span class="comment"># -n :后面接次数,每次command 指令执行时,要使用几个参数的意思。</span></span><br><span class="line"><span class="comment"># 当xargs 后面没有接任何的指令时,预设是以echo 来进行输出喔!</span></span><br><span class="line"></span><br><span class="line">$ <span class="built_in">cut</span> -d <span class="string">':'</span> -f 1 /etc/passwd | <span class="built_in">head</span> -n 3 | xargs -n 1 <span class="built_in">id</span></span><br><span class="line"><span class="comment"># uid=0(root) gid=0(root) groups=0(root)</span></span><br><span class="line"><span class="comment"># uid=1(bin) gid=1(bin) groups=1(bin)</span></span><br><span class="line"><span class="comment"># uid=2(daemon) gid=2(daemon) groups=2(daemon)</span></span><br><span class="line"><span class="comment"># 透过-n 来处理,一次给予一个参数,因此上述的结果就OK 正常的显示啰!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 同上,但是每次执行id时,都要询问使用者是否动作?</span></span><br><span class="line">$ <span class="built_in">cut</span> -d <span class="string">':'</span> -f 1 /etc/passwd | <span class="built_in">head</span> -n 3 | xargs -p -n 1 <span class="built_in">id</span> </span><br><span class="line"><span class="comment"># id root ?... y</span></span><br><span class="line"><span class="comment"># uid=0(root) gid=0(root) groups=0(root)</span></span><br><span class="line"><span class="comment"># id bin ?... y </span></span><br><span class="line"><span class="comment"># .....(底下省略).....</span></span><br><span class="line"><span class="comment"># 呵呵!这个-p 的选项可以让使用者的使用过程中,被询问到每个指令是否执行!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 将所有的/etc/passwd内的帐号都以id查阅,但查到sync就结束指令串 </span></span><br><span class="line">$ <span class="built_in">cut</span> -d <span class="string">':'</span> -f 1 /etc/passwd | xargs -e<span class="string">'sync'</span> -n 1 <span class="built_in">id</span> </span><br><span class="line"><span class="comment">#仔细与上面的案例做比较。也同时注意,那个-e'sync'是连在一起的,中间没有空白键。</span></span><br><span class="line"><span class="comment"># 上个例子当中,第六个参数是sync 啊,那么我们下达-e'sync' 后,则分析到sync 这个字串时,</span></span><br><span class="line"><span class="comment"># 后面的其他stdin 的内容就会被xargs 舍弃掉了!</span></span><br></pre></td></tr></tbody></table></figure><h3 id="关于减号---的用途">关于减号 - 的用途</h3><p>管线命令在bash 的连续的处理程序中是相当重要的!另外,在log file的分析当中也是相当重要的一环,所以请特别留意!另外,在管线命令当中,常常会使用到<strong>前一个指令的stdout作为这次的stdin</strong> , 某些指令需要用到档案名称(例如tar)来进行处理时,该stdin 与stdout 可以利用减号"-" 来替代, 举例来说:</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">mkdir</span> /tmp/homeback </span><br><span class="line">$ tar -cvf - /home | tar -xvf - -C /tmp/homeback</span><br></pre></td></tr></tbody></table></figure><p><strong>减号相当于stdin,stdout的跳转管道</strong></p></body></html>]]></content>
<summary type="html"><html><head></head><body><h2 id="快捷键">快捷键</h2>
<ul>
<li><code>^u</code> 向前删除所有; <code>^k</code> 向后删除所有</li>
<li><code>^a</code>(ahead)移至最前面,<code>^e</code>(end)移至最后</li>
</ul>
<h2 id="变量">变量</h2>
<h3 id="内置变量例如pathhomerandom">内置变量例如<code>PATH</code>,<code>HOME</code>,<code>RANDOM</code></h3>
<figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[dmtsai@study ~]$ <span class="built_in">declare</span> -i number=<span class="variable">$RANDOM</span>*10/32768 ; <span class="built_in">echo</span> <span class="variable">$number</span></span><br><span class="line">8 &lt;== 此時會隨機取出 0~9 之間的數值喔!</span><br></pre></td></tr></tbody></table></figure>
<ul>
<li><p>获取环境变量<code>env</code>(所有bash都具有的变量).获取环境变量和自订变量<code>set</code></p></li>
<li><p>将临时变量变为环境变量<code>export var</code>,获取当前的环境变量<code>export</code></p>
<p></p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">work=/home/s0me/tmp </span><br><span class="line"><span class="built_in">export</span> work <span class="comment">#当前bash和所有的子进程的环境变量,新的bash shell中并不会有此变量</span></span><br><span class="line"><span class="comment">#只能将某个变量设为子进程和当前进程的环境变量</span></span><br><span class="line"></span><br><span class="line">bash <span class="comment">#打开新的bash子进程</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$work</span> <span class="comment">#成功的进入了设定好的work目录</span></span><br><span class="line"><span class="built_in">exit</span> <span class="comment">#关闭子bash进程</span></span><br></pre></td></tr></tbody></table></figure><p></p></li>
</ul></body></html></summary>
<category term="linux" scheme="http://ljmeng.site/categories/linux/"/>
<category term="bash" scheme="http://ljmeng.site/categories/bash/"/>
<category term="linux" scheme="http://ljmeng.site/tags/linux/"/>
<category term="bash" scheme="http://ljmeng.site/tags/bash/"/>
</entry>
</feed>