0


linux基本指令(下)

文章目录

1.sort 指令

使用vim编辑器,在888.txt文件中输入内容

  1. [yzq@VM-8-8-centos 6.6]$ vim 888.txt
  2. [yzq@VM-8-8-centos 6.6]$ cat 888.txt
  3. 11112222333344444444443333338888
  • 这里vim编辑器的用法先不用了解,记住 使用 a 后输入你想要打印的内容
  • 最后使用 ESC :wq 退出vim编辑器

sort ——升序

对应文本内容按行为单位进行排序

  1. [yzq@VM-8-8-centos 6.6]$ sort 888.txt
  2. 11112222333333333344444444448888
  • sort排序规则:从左向右,每行的第一个字母开始按ascii值进行比较,谁的ascii值小就放在前面

sort -r ——降序

  1. [yzq@VM-8-8-centos 6.6]$ sort -r 888.txt
  2. 88884444444444333333333322221111

sort +文件 | uniq ——去重

再次使用vim ,将888.txt文件内容进行修改,使其拥有重复的1111 、2222、3333

  1. [yzq@VM-8-8-centos 6.6]$ vim 888.txt
  2. [yzq@VM-8-8-centos 6.6]$ cat 888.txt
  3. 111111112222222233333333
  • 这里vim编辑器的用法先不用了解,记住 使用 a 后输入你想要打印的内容
  • 最后使用 ESC :wq 退出vim编辑器
  1. [yzq@VM-8-8-centos 6.6]$ sort 888.txt | uniq
  2. 111122223333

把相邻的一样的文本,压缩只剩下一个 去重后,只剩下 1111 2222 3333

2. find - name 指令

根据指定选项完成文件搜索

  1. [yzq@VM-8-8-centos 6.6]$ find ~-name test.c
  2. /home/mydir/game/the-first-stu-wirting/通讯录 文件/通讯录 文件/test.c
  3. /home/mydir/game/the-first-stu-wirting/文件/文件/test.c
  4. /home/mydir/lesson5/test.c
  • ~ 代表当前目录的家目录
  • find ~ -name test.c 代表 在家目录中test.c文件全部被查找到

3. which 指令

搜索对应指令,在对应的路径

  1. [yzq@VM-8-8-centos 6.6]$ which pwd
  2. /usr/bin/pwd

说明pwd指令在 /usr/bin 路径中

alias ——起别名

  1. [yzq@VM-8-8-centos 6.6]$ which ls
  2. alias ls='ls --color=auto'/usr/bin/ls

这里出现了一个alias,是用来给特定的命令起别名
对此我们可以验证一下

  1. [yzq@VM-8-8-centos 6.6]$ ls -la -i -n
  2. total 12786436 drwxrwxr-x 2100210024096 Nov 2310:41.657483 drwx------15100210024096 Nov 2310:41..786446-rw-rw-r--11002100231 Nov 2310:41888.txt
  3. [yzq@VM-8-8-centos 6.6]$ alias myls='ls -la -i -n'[yzq@VM-8-8-centos 6.6]$ myls
  4. total 12786436 drwxrwxr-x 2100210024096 Nov 2310:41.657483 drwx------15100210024096 Nov 2310:41..786446-rw-rw-r--11002100231 Nov 2310:41888.txt
  • ls -la -i -n 输出的结果 与起别名后 myls 的结果相同
  1. [yzq@VM-8-8-centos 6.6]$ which myls
  2. alias myls='ls -la -i -n'/usr/bin/ls

再次使用 which myls ,就显示了 将 ls -la -i -n 起别名为 myls

4. whereis 指令

系统默认路径下指定名称的文件、程序、或者归档文件(压缩包)

  1. [yzq@VM-8-8-centos 6.6]$ whereis ls
  2. ls:/usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
  • 既找到 ls程序,又把程序配套的man手册对应的内容也显示出来了

5. grep指令

1.作用

文本行过滤工具
将指定文本内容按照特定关键字来进行按行筛选

这里就要用到上一节提到的1——1000的带有编号的hello wold 的创建:linux基本指令(中)

  1. [yzq@VM-8-8-centos 6.6]$ grep '88' test.txt
  2. hello world [88]
  3. hello world [188]
  4. hello world [288]
  5. hello world [388]
  6. hello world [488]
  7. hello world [588]
  8. hello world [688]
  9. hello world [788]
  10. hello world [880]
  11. hello world [881]
  12. hello world [882]
  13. hello world [883]
  14. hello world [884]
  15. hello world [885]
  16. hello world [886]
  17. hello world [887]
  18. hello world [888]
  19. hello world [889]
  20. hello world [988]

在test.txt文件中 搜索 带有88的内容

2. grep -n

  1. [yzq@VM-8-8-centos 6.6]$ grep -n '88' test.txt
  2. 89:hello world [88]189:hello world [188]289:hello world [288]389:hello world [388]489:hello world [488]589:hello world [588]689:hello world [688]789:hello world [788]881:hello world [880]882:hello world [881]883:hello world [882]884:hello world [883]885:hello world [884]886:hello world [885]887:hello world [886]888:hello world [887]889:hello world [888]890:hello world [889]989:hello world [988]

对应行的行号会被带上

3.grep - v

反向匹配
首先使用vim,将888.txt的内容改变

  1. [yzq@VM-8-8-centos 6.6]$ vim 888.txt
  2. [yzq@VM-8-8-centos 6.6]$ cat 888.txt
  3. aaaa
  4. bbbb
  5. cccc
  6. AAAA
  7. BBBB
  8. CCCC

这里vim的问题就不说了,有需要就去从头看看vim的用法

  1. [yzq@VM-8-8-centos 6.6]$ grep 'aaaa'-v 888.txt
  2. bbbb
  3. cccc
  4. AAAA
  5. BBBB
  6. CCCC
  • 除了包含 aaaa文本内容的显示全部出来

4. grep - i

忽略大小写

  1. [yzq@VM-8-8-centos 6.6]$ grep -i 'aaaa'888.txt
  2. aaaa
  3. AAAA

6 .zip指令

1. 安装

使用前需要安装下

  1. [yzq@VM-8-8-centos 6.6]$ yum install -y zip unzip

2. 打包

  1. zip 文件名.zip 文件名
  1. [yzq@VM-8-8-centos ~]$ ls
  2. 6.69.9 dir game lesson5 mk mkdir my mybin test
  3. [yzq@VM-8-8-centos ~]$ zip test.zip test
  4. adding: test/(stored 0%)[yzq@VM-8-8-centos ~]$ ls
  5. 6.69.9 dir game lesson5 mk mkdir my mybin test test.zip

这里使用zip 对test目录进行打包后,会出现 test.zip的压缩包

3. 解包

  1. unzip 文件名.zip
  1. [yzq@VM-8-8-centos ~]$ mv test.zip my
  2. [yzq@VM-8-8-centos ~]$ cd my
  3. [yzq@VM-8-8-centos my]$ ls
  4. test.zip
  5. [yzq@VM-8-8-centos my]$ unzip test.zip
  6. Archive: test.zip
  7. creating: test/[yzq@VM-8-8-centos my]$ tree test
  8. test
  9. 0 directories,0 files

将test.zip压缩包剪切到my目录下,

  1. 解包后发现没有数据存在

是因为

  1. 打包的时候没有把里面的东西 打包并压缩

zip -r

将里面的内容也打包并压缩

  1. zip -r 文件名.zip 文件名
  1. 6.69.9 dir game lesson5 mk mkdir my mybin test
  2. [yzq@VM-8-8-centos ~]$ zip -r test.zip test
  3. adding: test/(stored 0%)
  4. adding: test/makefile(deflated 16%)
  5. adding: test/mytest(deflated 71%)
  6. adding: test/mytest.c(deflated 38%)
  7. adding: test/mytest_d(deflated 70%)[yzq@VM-8-8-centos ~]$ ls
  8. 6.69.9 dir game lesson5 mk mkdir my mybin test test.zip
  9. [yzq@VM-8-8-centos ~]$ mv test.zip my
  10. [yzq@VM-8-8-centos ~]$ cd my
  11. [yzq@VM-8-8-centos my]$ ls
  12. test test.zip
  13. [yzq@VM-8-8-centos my]$ unzip test.zip
  14. Archive: test.zip
  15. inflating: test/makefile
  16. inflating: test/mytest
  17. inflating: test/mytest.c
  18. inflating: test/mytest_d
  19. [yzq@VM-8-8-centos my]$ tree test
  20. test
  21. |-- makefile
  22. |-- mytest
  23. |-- mytest.c
  24. `-- mytest_d
  25. 0 directories,4 files

此时使用 zip -r 将test 压缩成 test .zip的压缩包后,再剪切到my目录中打开
发现有test内部的内容啦

4. unzip -d

  1. 解包到指定目录下

需要注意的是 虽然解包了 但原有位置的.zip依旧存在

  1. 6.69.9 dir game lesson5 mk mkdir my mybin test
  2. [yzq@VM-8-8-centos ~]$ zip -r test.zip test
  3. adding: test/(stored 0%)
  4. adding: test/makefile(deflated 16%)
  5. adding: test/mytest(deflated 71%)
  6. adding: test/mytest.c(deflated 38%)
  7. adding: test/mytest_d(deflated 70%)[yzq@VM-8-8-centos ~]$ ls
  8. 6.69.9 dir game lesson5 mk mkdir my mybin test test.zip
  9. [yzq@VM-8-8-centos ~]$ unzip test.zip -d 6.6
  10. Archive: test.zip
  11. creating:6.6/test/
  12. inflating:6.6/test/makefile
  13. inflating:6.6/test/mytest
  14. inflating:6.6/test/mytest.c
  15. inflating:6.6/test/mytest_d
  16. [yzq@VM-8-8-centos ~]$ cd 6.6[yzq@VM-8-8-centos 6.6]$ ls
  17. 888.txt test test.txt

在这里插入图片描述

在test的所处目录中,使用unzip -d 将test.zip 压缩包传入到6.6中,
就不用使用mv剪切了

7. tar 指令

1.tar -czf ——打包

  • tar - c :创建一个新的归档文件即压缩包
  • tar - z : 使用打包的同时可以进行压缩
  • tar - f : 给归档文件一个名字 建议把 f 放在最后
  • tar -czf + 文件名.tgz +文件名
  1. [yzq@VM-8-8-centos ~]$ ls
  2. 6.69.9 dir game lesson5 mk mkdir my mybin test
  3. [yzq@VM-8-8-centos ~]$ tar -czf test.tgz test
  4. [yzq@VM-8-8-centos ~]$ ls
  5. 6.69.9 dir game lesson5 mk mkdir my mybin test test.tgz

在这里插入图片描述

压缩包 以 .tgz 为结尾

2.tar -xzf —— 解包

  • tar -x 解开文件
  • tar -xzf 文件名.tgz
  1. [yzq@VM-8-8-centos ~]$ tar -xzf test.tgz
  2. [yzq@VM-8-8-centos ~]$ ls
  3. 6.69.9 dir game lesson5 mk mkdir my mybin test test.tgz
  4. [yzq@VM-8-8-centos ~]$ tree test
  5. test
  6. |-- makefile
  7. |-- mytest
  8. |-- mytest.c
  9. `-- mytest_d
  10. 0 directories,4 files

3.tar -ztvf ——直接查看压缩包内的内容

  • tar -ztvf +文件名.tgz
  • tar -t 不解压 ,直接看压缩包中有什么
  • tar -v :将文件显示更详细
  1. 6.69.9 dir game lesson5 mk mkdir my mybin test test.tgz
  2. [yzq@VM-8-8-centos ~]$ tar -ztvf test.tgz
  3. drwxrwxr-x yzq/yzq 02022-11-2306:37 test/-rw-rw-r-- yzq/yzq 752022-10-1518:29 test/makefile
  4. -rwxrwxr-x yzq/yzq 84412022-11-2306:37 test/mytest
  5. -rw-rw-r-- yzq/yzq 2782022-10-1614:03 test/mytest.c
  6. -rwxrwxr-x yzq/yzq 96482022-10-1518:30 test/mytest_d

4. tar -xzf 文件名.tgz -C

解包到指定目录下

  • tar -xzf 文件名.tgz -C
  1. [yzq@VM-8-8-centos ~]$ tar czf test.tgz test
  2. [yzq@VM-8-8-centos ~]$ ls
  3. 6.69.9 dir game lesson5 mk mkdir my mybin test test.tgz
  4. [yzq@VM-8-8-centos ~]$ tar -xzf test.tgz -C 6.6[yzq@VM-8-8-centos ~]$ ls
  5. 6.69.9 dir game lesson5 mk mkdir my mybin test test.tgz
  6. [yzq@VM-8-8-centos ~]$ cd 6.6[yzq@VM-8-8-centos 6.6]$ ls
  7. 888.txt test test.txt
  8. [yzq@VM-8-8-centos 6.6]$ tree test
  9. test
  10. |-- makefile
  11. |-- mytest
  12. |-- mytest.c
  13. `-- mytest_d
  14. 0 directories,4 files

在这里插入图片描述

将 test的压缩包 test.tgz ,解包到6.6目录中

8. bc 指令

linux上计算器,看可以进行加减乘除,也可以进行精度计算

  1. [yzq@VM-8-8-centos ~]$ bc
  2. bc 1.06.95
  3. Copyright 1991-1994,1997,1998,2000,2004,2006 Free Software Foundation, Inc.
  4. This is free software with ABSOLUTELY NO WARRANTY.
  5. For details type `warranty'.1+125*2102.0*5.010.05.0/4.01
标签: linux vim 运维

本文转载自: https://blog.csdn.net/qq_62939852/article/details/127995674
版权归原作者 风起、风落 所有, 如有侵权,请联系我们删除。

“linux基本指令(下)”的评论:

还没有评论