@@ -226,20 +226,40 @@ Linux系统的命令通常都是如下所示的格式:
226226    [root@iZwz97tbgo9lkabnat2lo8Z ~]# !454 
227227    ``` 
228228
229-     > 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令。 
229+     > 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令 。 
230230
231231### 实用程序 
232232
233233#### 文件和文件夹操作 
234234
2352351. 创建/删除目录 - **mkdir** / **rmdir**。 
236236
237+    ```Shell 
238+     
239+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir abc 
240+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir -p xyz/abc 
241+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# rmdir abc 
242+    ``` 
243+ 
2372442. 创建/删除文件 - **touch** / **rm**。 
238245
246+    ```Shell 
247+     
248+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch readme.txt 
249+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# touch error.txt 
250+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm error.txt 
251+    rm: remove regular empty file ‘error.txt’? y 
252+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm -rf xyz 
253+    ``` 
254+ 
239255   - touch命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间: 
240-      - 更改内容的时间(mtime) 
241-      - 更改权限的时间(ctime) 
242-      - 最后访问时间(atime) 
256+      - 更改内容的时间 - mtime。 
257+      - 更改权限的时间 - ctime。 
258+      - 最后访问时间 - atime。 
259+    - rm的几个重要参数: 
260+      - -i:交互式删除,每个删除项都会进行询问。 
261+      - -r:删除目录并递归的删除目录中的文件和目录。 
262+      - -f:强制删除,忽略不存在的文件,没有任何提示。 
243263
2442643. 切换和查看当前工作目录 - **cd** / **pwd**。 
245265
@@ -250,33 +270,189 @@ Linux系统的命令通常都是如下所示的格式:
250270   - -l:以长格式查看文件和目录。 
251271   - -a:显示以点开头的文件和目录(隐藏文件)。 
252272   - -R:遇到目录要进行递归展开(继续列出目录下面的文件和目录)。 
273+    - -d:只列出目录,不列出其他内容。 
274+    - -S/-t:按大小/时间排序。 
253275
2542765. 查看文件内容 - **cat** / **head** / **tail** / **more** / **less**。 
255277
278+    ```Shell 
279+     
280+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.sohu.com/ -O sohu.html 
281+    --2018-06-20 18:42:34--  http://www.sohu.com/ 
282+    Resolving www.sohu.com (www.sohu.com)... 14.18.240.6 
283+    Connecting to www.sohu.com (www.sohu.com)|14.18.240.6|:80... connected. 
284+    HTTP request sent, awaiting response... 200 OK 
285+    Length: 212527 (208K) [text/html] 
286+    Saving to: ‘sohu.html’ 
287+    100%[==================================================>] 212,527     --.-K/s   in 0.03s 
288+    2018-06-20 18:42:34 (7.48 MB/s) - ‘sohu.html’ saved [212527/212527] 
289+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sohu.html 
290+    ... 
291+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# head -10 sohu.html 
292+    <!DOCTYPE html> 
293+    <html> 
294+    <head> 
295+    <title>搜狐</title> 
296+    <meta name="Keywords" content="搜狐,门户网站,新媒体,网络媒体,新闻,财经,体育,娱乐,时尚,汽车,房产,科技,图片,论坛,微博,博客,视频,电影,电视剧"/> 
297+    <meta name="Description" content="搜狐网为用户提供24小时不间断的最新资讯,及搜索、邮件等网络服务。内容包括全球热点事件、突发新闻、时事评论、热播影视剧、体育赛事、行业动态、生活服务信息,以及论坛、博客、微博、我的搜狐等互动空间。" /> 
298+    <meta name="shenma-site-verification" content="1237e4d02a3d8d73e96cbd97b699e9c3_1504254750"> 
299+    <meta charset="utf-8"/> 
300+    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> 
301+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# tail -2 sohu.html 
302+    </body> 
303+    </html> 
304+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# less sohu.html 
305+    ... 
306+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat -n sohu.html | more 
307+    ... 
308+    ``` 
309+ 
2563106. 拷贝/移动文件 - **cp** / **mv**。 
257311
312+    ```Shell 
313+     
314+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir backup 
315+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cp sohu.html backup/ 
316+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd backup 
317+    [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls 
318+    sohu.html 
319+    [root@iZwz97tbgo9lkabnat2lo8Z backup]# mv sohu.html sohu_index.html 
320+    [root@iZwz97tbgo9lkabnat2lo8Z backup]# ls 
321+    sohu_index.html 
322+    ``` 
323+ 
2583247. 查看文件及内容 - **find** / **grep**。 
259325
260326   ```Shell 
261327    
262-    [root@izwz97tbgo9lkabnat2lo8z  ~]# find -name *.html 
263-    ./index .html 
264-    ./code/index .html 
328+    [root@iZwz97tbgo9lkabnat2lo8Z  ~]# find /  -name " *.html"  
329+    /root/sohu .html 
330+    /root/backup/sohu_index .html 
265331   [root@izwz97tbgo9lkabnat2lo8z ~]# find . -atime 7 -type f -print 
266332   [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -size +2k 
267333   [root@izwz97tbgo9lkabnat2lo8z ~]# find . -type f -name "*.swp" -delete 
268-    [root@izwz97tbgo9lkabnat2lo8z ~]# grep "<script>" . -R -n 
269-    ./index.html:15:                <script> 
270-    ./code/index.html:2884: <script> 
271-    ./code/foo.html:2:<!--STATUS OK--><html> <head><meta ... 
334+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep "<script>" sohu.html -n 
335+    20:<script> 
336+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# grep -E \<\/?script.*\> sohu.html -n 
337+    20:<script> 
338+    22:</script> 
339+    24:<script src="//statics.itc.cn/web/v3/static/js/es5-shim-08e41cfc3e.min.js"></script> 
340+    25:<script src="//statics.itc.cn/web/v3/static/js/es5-sham-1d5fa1124b.min.js"></script> 
341+    26:<script src="//statics.itc.cn/web/v3/static/js/html5shiv-21fc8c2ba6.js"></script> 
342+    29:<script type="text/javascript"> 
343+    52:</script> 
344+    ... 
272345   ``` 
273346
274- 8. 符号链接 - **ln**。 
347+ 8. 链接 - **ln**。 
348+ 
349+    ```Shell 
350+     
351+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html 
352+    -rw-r--r-- 1 root root 212131 Jun 20 19:15 sohu.html 
353+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup 
354+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html 
355+    -rw-r--r-- 2 root root 212131 Jun 20 19:15 sohu.html 
356+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln /root/sohu.html /root/backup/sohu_backup2 
357+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html 
358+    -rw-r--r-- 3 root root 212131 Jun 20 19:15 sohu.html 
359+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /etc/centos-release sysinfo 
360+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sysinfo 
361+    lrwxrwxrwx 1 root root 19 Jun 20 19:21 sysinfo -> /etc/centos-release 
362+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat sysinfo 
363+    CentOS Linux release 7.4.1708 (Core) 
364+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release 
365+    CentOS Linux release 7.4.1708 (Core) 
366+    ``` 
367+ 
368+    > 说明:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。 
275369
2763709. 压缩和归档 - **gzip** / **gunzip** / **xz** / **tar**。 
277371
372+    ```Shell 
373+     
374+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz 
375+    --2018-06-20 19:29:59--  http://download.redis.io/releases/redis-4.0.10.tar.gz 
376+    Resolving download.redis.io (download.redis.io)... 109.74.203.151 
377+    Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. 
378+    HTTP request sent, awaiting response... 200 OK 
379+    Length: 1738465 (1.7M) [application/x-gzip] 
380+    Saving to: ‘redis-4.0.10.tar.gz’ 
381+    100%[==================================================>] 1,738,465   70.1KB/s   in 74s 
382+    2018-06-20 19:31:14 (22.9 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465] 
383+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* 
384+    redis-4.0.10.tar.gz 
385+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-4.0.10.tar.gz 
386+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* 
387+    redis-4.0.10.tar 
388+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-4.0.10.tar 
389+    redis-4.0.10/ 
390+    redis-4.0.10/.gitignore 
391+    redis-4.0.10/00-RELEASENOTES 
392+    redis-4.0.10/BUGS 
393+    redis-4.0.10/CONTRIBUTING 
394+    redis-4.0.10/COPYING 
395+    redis-4.0.10/INSTALL 
396+    redis-4.0.10/MANIFESTO 
397+    redis-4.0.10/Makefile 
398+    redis-4.0.10/README.md 
399+    redis-4.0.10/deps/ 
400+    redis-4.0.10/deps/Makefile 
401+    redis-4.0.10/deps/README.md 
402+    ... 
403+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* 
404+    redis-4.0.10.tar 
405+    redis-4.0.10: 
406+    00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests 
407+    BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils 
408+    CONTRIBUTING     INSTALL  README.md  runtest-cluster  src 
409+    ``` 
410+ 
27841110. 其他工具 - **sort** / **uniq** / **diff** / **tr** / **cut** / **paste** / **file** / **wc**。 
279412
413+    ```Shell 
414+     
415+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat 1.txt 
416+    grape 
417+    apple 
418+    pitaya 
419+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat 2.txt 
420+    100 
421+    200 
422+    300 
423+    400 
424+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste 1.txt 2.txt 
425+    grape   100 
426+    apple   200 
427+    pitaya  300 
428+            400 
429+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste 1.txt 2.txt > 3.txt 
430+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 3.txt 
431+    pe      10 
432+    le      20 
433+    aya     3 
434+    0 
435+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat 3.txt | tr '  \t '  '  ,' 
436+    grape,100 
437+    apple,200 
438+    pitaya,300 
439+    ,400 
440+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png 
441+    --2018-06-20 18:46:53--  https://www.baidu.com/img/bd_logo1.png 
442+    Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244 
443+    Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:443... connected. 
444+    HTTP request sent, awaiting response... 200 OK 
445+    Length: 7877 (7.7K) [image/png] 
446+    Saving to: ‘bd_logo1.png’ 
447+    100%[==================================================>] 7,877       --.-K/s   in 0s 
448+    2018-06-20 18:46:53 (118 MB/s) - ‘bd_logo1.png’ saved [7877/7877][root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png 
449+    bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced 
450+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html 
451+      2979   6355 212527 sohu.html 
452+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html 
453+    2979 sohu.html 
454+    ``` 
455+ 
280456#### 管道和重定向 
281457
2824581. 管道的使用 - **\|**。 
@@ -312,7 +488,7 @@ Linux系统的命令通常都是如下所示的格式:
312488
313489   ```Shell 
314490    
315-    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat ReadMe .txt 
491+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme .txt 
316492   banana 
317493   apple 
318494   grape 
@@ -321,8 +497,8 @@ Linux系统的命令通常都是如下所示的格式:
321497   watermelon 
322498   pear 
323499   pitaya 
324-    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat ReadMe .txt | sort | uniq > Result .txt 
325-    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat Result .txt 
500+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat readme .txt | sort | uniq > result .txt 
501+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat result .txt 
326502   apple 
327503   banana 
328504   grape 
@@ -333,6 +509,21 @@ Linux系统的命令通常都是如下所示的格式:
333509
3345103. 输入重定向 - **\<**。 
335511
512+    ```Shell 
513+     
514+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo '  hello, world! '  > hello.txt
515+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt 
516+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# 
517+    Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:05 2018): 
518+    hello, world! 
519+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# echo '  I will show you some code.'  >> hello.txt
520+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# wall < hello.txt 
521+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# 
522+    Broadcast message from root@iZwz97tbgo9lkabnat2lo8Z (Wed Jun 20 19:43:55 2018): 
523+    hello, world! 
524+    I will show you some code. 
525+    ``` 
526+ 
336527#### 别名 
337528
3385291. **alias** 
@@ -387,22 +578,14 @@ Linux系统的命令通常都是如下所示的格式:
387578
3885793. 给用户发送消息 - **mesg** / **write** / **wall** / **mail**。 
389580
390-    ```Shell 
391-     
392-     
393-    ``` 
394- 
395-     
396581
397582### 文件系统 
398583
399584#### 文件和路径 
400585
401- 1. 命名规则 
402- 2. 扩展名 
403- 3. 隐藏文件 
404- 4. 工作目录和主目录 
405- 5. 绝对路径和相对路径 
586+ 1. 命名规则:文件名的最大长度与文件系统类型有关,一般情况下,文件名不应该超过255个字符,虽然绝大多数的字符都可以用于文件名,但是最好使用英文大小写字母、数字、下划线、点这样的符号。文件名中虽然可以使用空格,但应该尽可能避免使用空格,否则在输入文件名时需要用将文件名放在双引号中或者通过`\`对空格进行转义。 
587+ 2. 扩展名:在Linux系统下文件的扩展名是可选的,但是使用扩展名有助于对文件内容的理解。有些应用程序要通过扩展名来识别文件,但是更多的应用程序并不依赖文件的扩展名,就像`file`命令在识别文件时并不是依据扩展名来判定文件的类型。 
588+ 3. 隐藏文件:以点开头的文件在Linux系统中是隐藏文件(不可见文件)。 
406589
407590#### 目录结构 
408591
@@ -459,12 +642,12 @@ Linux系统的命令通常都是如下所示的格式:
459642        
460643    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l 
461644    ... 
462-     -rw-r--r--  1 root root     54 Jun 20 10:06 ReadMe .txt 
645+     -rw-r--r--  1 root root     54 Jun 20 10:06 readme .txt 
463646    ... 
464-     [root@iZwz97tbgo9lkabnat2lo8Z ~]# chown hellokitty ReadMe .txt 
647+     [root@iZwz97tbgo9lkabnat2lo8Z ~]# chown hellokitty readme .txt 
465648    [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l 
466649    ... 
467-     -rw-r--r--  1 hellokitty root     54 Jun 20 10:06 ReadMe .txt 
650+     -rw-r--r--  1 hellokitty root     54 Jun 20 10:06 readme .txt 
468651    ... 
469652    ``` 
470653
@@ -478,33 +661,46 @@ Linux系统的命令通常都是如下所示的格式:
478661
479662### 编辑器vim 
480663
481- 1. 启动和退出  
664+ 1. 启动vim。  
482665
483- 2. 命令模式和编辑模式 
666+    ```Shell 
667+     
668+    [root@iZwz97tbgo9lkabnat2lo8Z ~]# vim guess.py 
669+    ``` 
484670
485- 3. 光标操作 
671+ 2. 命令模式、编辑模式和末行模式:启动vim进入的是命令模式,在命令模式下输入英文字母`i`会进入编辑模式,屏幕下方出现`-- INSERT --`提示;在编辑模式下按下`Esc`会回到命令模式,此时如果输入英文`:`会进入末行模式,在末行模式下输入`q!`可以在不保存当前工作的情况下强行退出vim,如果希望执行保存退出,则应该在末行模式下输入`wq`。 
672+ 
673+ 3. 光标操作。 
674+ 
675+    - 在命令模式下可以通过`h`、`j`、`k`、`l`来控制光标向左、下、上、右的方向移动,可以在字母前输入数字来表示移动的距离,例如:`10h`表示向左移动10个字符。 
676+    - 在命令模式下可以通过`Ctrl+y`和`Ctrl+e`来实现向上、向下滚动一行文本的操作,可以通过`Ctrl+f`和`Ctrl+b`来实现向前和向后翻页的操作。 
677+    - 在命令模式下可以通过输入英文字母`G`将光标移到文件的末尾,可以通过`gg`将光标移到文件的开始,也可以通过在`G`前输入数字来将光标移动到指定的行。 
486678
4876794. 文本操作 
488680
681+    - 删除 
682+    - 复制和粘贴 
683+    - 撤销和恢复 
684+ 
4896855. 查找和替换 
490686
491-    - /正则表达式 
492-    - :n1,n2s/正则表达式/替换后的内容/gice 
493-      - g  - global 
494-      - i  - ignore case 
495-      - c  - confirm 
496-      - e  - error 
687+    - ` /正则表达式`  
688+    - ` :n1,n2s/正则表达式/替换后的内容/gice`  
689+      - `g`  - global:全局匹配。  
690+      - `i`  - ignore case:忽略大小写匹配。  
691+      - `c`  - confirm:替换时需要确认。  
692+      - `e`  - error:忽略错误。  
497693
498- 6. 参数设定 
694+ 6. 参数设定:在输入`:`进入末行模式后可以对vim进行设定。  
499695
500-    - : set ts=4 
501-    - : set nu 
502-    - : syntax on 
696+    - 设置Tab键的空格数:` set ts=4`  
697+    - 设置显示/不显示行号:` set nu` / `set nonu`  
698+    - 设置启动/关闭高亮语法:` syntax on` / `syntax off`  
503699
5047007. 高级技巧 
505701
506702   - 映射快捷键 
507-      - inoremap key:... 
703+      - ` inoremap key:...`  
508704   - 录制宏 
509705     - 在命令模式下输入`qa`开始录制宏(也可以是`qb`、`qc`、`qd`) 
510706     - 执行你的操作,这些操作都会被录制下来 
0 commit comments