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
正则表达式
通配符用来查找文件,正则用来过滤文件内容
| 正则分类 | 缩写 | 英文 |
|---|---|---|
| 基础正则表达式 | BRE | basic regular expression |
| 扩展正则 | ERE | extended 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
-



