shell特殊符号、cut_sort_wc_uniq命令和tee_tr_split命令

shell特殊符号

  • * 任意个任意字符

  • ? 任意一个字符

  • # 注释字符

  • \ 脱义字符

  • | 管道符

  • $ 变量前缀 , !$ 组合,正则里面表示行尾

  • ; 多条命令写到一行,用分号分割

  • ~ 用户家目录,后面正则表达式表示匹配符

  • & 放到命令后面,会把命令丢到后台

  • > >> 2> 2>> &>

  • [] 指定字符中的一个,[0-9],[a-zA-Z],[abc]

  • || 和 && , 用于命令之间

cut_sort_wc_uniq命令

cut 分隔

选项

-d 分隔符

-f 指定段号

[root@localhost~]#cat/etc/passwd|head-2|cut-d":"-f1
root
bin
[root@localhost~]#cat/etc/passwd|head-2|cut-d":"-f1,2
root:x
bin:x
[root@localhost~]#cat/etc/passwd|head-2|cut-d":"-f1-3
root:x:0
bin:x:1

-c 指定第几个字符

[root@localhost~]#cat/etc/passwd|head-2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost~]#cat/etc/passwd|head-2|cut-c4
t
:

sort 排序

实例:

dbfc28568903c4c798a6ee774b83059d.png-wh_

选项

-n 以数字排序:字母和特殊符号标记为0

-r 反序

-t 分隔符 -kn1/-kn1,n2

wc

选项

-l 统计行数

[root@localhosta]#cat1.txt|head-1
root:x:0:0:root:/root:/bin/bash
[root@localhosta]#cat1.txt|head-1|wc-l
1

-m 统计字符数

[root@localhosta]#cat1.txt|head-1|wc-m
32
[root@localhosta]#cat1.txt|head-1|cat-A
root:x:0:0:root:/root:/bin/bash$

-w 统计词:以空白字符做为分隔符

[root@localhosta]#echo'aaabbb,wwww222211$a'|wc-w
3

uniq 去重复

#uniq1.txt需要排序后再去重
#sort1.txt|uniq
[root@localhosta]#echo'2222
>1111
>2222
>1111
>1bx
>2bx
>1bx'|sort|uniq
1111
1bx
2222
2bx
#uniq-c统计行数//sort1.txt|uniq-c
[root@localhosta]#echo'222
111
222
1bx
2bx
1bx'|sort|uniq-c
1111
21bx
2222
12bx

tee_tr_split命令

tee 和>类似,重定向的同时还在屏幕显示 -a //追加

root@localhosta]#echo'2222'|tee2.txt
2222
[root@localhosta]#cat2.txt
2222
[root@localhosta]#echo'2222'|tee-a2.txt
2222
[root@localhosta]#cat2.txt
2222
2222

tr 替换字符,tr 'a' 'b' ,大小写替换tr '[a-z]' '[A-Z]'

[root@localhosta]#echo'a'|tr'a''A'
A

split 切割,-b大小 (认单位字节),-l 行数

[root@localhosta]#du-sh1.txt
4.0K	1.txt
[root@localhosta]#split-b1001.txt
[root@localhosta]#ls
1.txtxaaxabxacxadxae
[root@localhosta]#du-sh
24K	.
[root@localhosta]#ls-l
总用量24
-rw-r--r--.1rootroot46111月1810:341.txt
-rw-r--r--.1rootroot10011月1811:45xaa
-rw-r--r--.1rootroot10011月1811:45xab
-rw-r--r--.1rootroot10011月1811:45xac
-rw-r--r--.1rootroot10011月1811:45xad

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...