栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

从零学习网络运维Linux-day12

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从零学习网络运维Linux-day12

zip命令 使用zip进行压缩

 [root@theboy82 ~]# zip zip.zip 1.txt
   adding: 1.txt (deflated 17%)
 [root@theboy82 ~]# ll
 total 20
 -rw-r--r--. 2 root root   12 May 13 14:08 1.txt
 -rw-r--r--. 1 root root  170 May 14 22:30 zip.zip
 ​
 [root@theboy82 ~]# unzip zip.zip
 Archive:  zip.zip
 replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
   inflating: 1.txt                   
 [root@theboy82 ~]# ll
 total 20
 -rw-r--r--. 1 root root   12 May 13 14:08 1.txt
 -rw-r--r--. 1 root root  170 May 14 22:30 zip.zip

通配符

作用:用来查找文件名(不是查看过滤文件内容)

重启网卡的命令:ifdown eth0 && ifup eth0 #相当于systemctl restart network

符号作用常用格式
*表示任意字符串、所有
表示单个字符
[]或者的含义、可选择[123] [1-3]
{}生成序列(数字 字母){1..3}{a..z}
取反[!123]
^取反[^123]
``将执行后的结果给其他命令调用
$()将执行后的结果给其他命令调用

od命令

位置:/usr/bin/od 权限:所有用户

作用:非纯文本文件内容查阅

 用法:od  [-t   TYPE]  文件
 ​
 -t 后面可以接各种类型(TYPE)的的输出
 ​
 a :理由默认的字符来输出
 ​
 c :利用ASCII字符输出
 ​
 d[size] : 利用十进制来输出数据,每个整数占size个bytes
 ​
 f[size] :  利用浮点数来输出数据,每个整数占size个bytes
 ​
 o[size] : 利用八进制来输出数据,每个整数占size个bytes
 ​
 x[size] :  利用十六进制来输出数据,每个整数占size个bytes

|wc -L:查看当前结果最长行的字符串个数

 [root@theboy82 ~]# cat passwd|wc -L
 99
 ​

通配符实例

 [root@theboy82 ~]# ll aa?[1-5].*
 -rw-r--r--. 1 root root 0 May 14 23:00 aa01.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa02.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa03.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa04.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa05.txt
 ​
 [root@theboy82 ~]# ll *?{1..5}.*
 -rw-r--r--. 1 root root 0 May 14 23:00 aa01.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa02.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa03.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa04.txt
 -rw-r--r--. 1 root root 0 May 14 23:00 aa05.txt
 ​
 [root@theboy82 ~]# ll $(find -type f -name *?5*)
 -rw-r--r--. 1 root root 0 May 14 23:00 ./aa05.txt
 ​

正则表达式

通配符用来查找文件,正则用来过滤文件内容

正则分类缩写英文
基础正则表达式BREbasic regular expression
扩展正则EREextended regular expression

grep

grep是别名 在执行时 系统自动加了--color参数(centos6.x默认没有此参数)

 [root@theboy82 ~]# alias grep
 alias grep='grep --color=auto'
  • 语法结构 grep ‘ ’ 文件

    • -i#不区分大小写

    • -v#取反

基础正则

符号作用常用格式
^过滤以^后内容开头的行内容grep '^内容' 文件名
$过滤以$前内容结尾的行内容grep '内容$' 文件名
.匹配任意单个字符 不匹配空行和空格grep . 文件名
*前一个字符连续出现0次或0次以上grep '*内容' 文件名
.*表示所有,类似通配符*grep '.*' 文件名
[]或者的含义括号中的符号皆为普通字符(第一个^除外)grep '[123]' 文件名
[^]取反(只有第一个表示取反,其余为普通字符)grep '内容' 文件名
  • *如果没有过滤到内容,会显示所有文件内容

  • .* 贪婪匹配 尽可能的匹配

  • 注意:cat -A查看,会在内容行后面显示$

    •  [root@theboy82 ~]# cat -A 1.txt
       i have pen$
       i have chiken$
       pen$
       chiken$
       $

  • 过滤所有的空格

    •  [root@theboy82 ~]# grep ' ' 1.txt
       i have pen
       i have chiken

  • 过滤文件中的空行

    •  [root@theboy82 ~]# grep '^$' 1.txt
       ​
       ​
       ​
       [root@theboy82 ~]# cat 1.txt
       i have pen
       ​
       i have chiken
       pen
       ​
       chiken
  • 显示行号

    •  [root@theboy82 ~]# grep -n '^$' 1.txt
       2:
       5:
       7:
  • 匹配单个任意字符

    •  [root@theboy82 ~]# grep . 1.txt
       i have pen
       i have chiken
       pen
       chiken
    • -o:显示匹配执行过程

    •  [root@theboy82 ~]# grep -o . 1.txt
       i
       ​
       h
       .
       .
       .#省略中间太多
       n
  • 查找以.结尾的行

    •  [root@theboy82 ~]# grep '.$' 1.txt
       i have chiken.

扩展正则

grep支持扩展正则需使用egrep或者grep -E

符号作用格式
+前一个字符出现一次或1次以上 作为一个整体egrep ‘内容+’ 文件
|或者egrep '内容|内容' 文件
{n,m} {n}前一个字符出现n次,最多出现m次;前一个字符出现n次egrep ‘内容{n,m}’ 文件
  • 过滤除了空行或者#开头的行

    •  [root@theboy82 ~]# egrep -v '^$|^#' 1.txt
       i have pen
       i have chiken.
       LANG=zh_CN.UTF-8
       LANG=zh_CN.UTF-8
       pen
       aaaaabbbb
       AAAABBBB
       chiken
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/887724.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号