常用的管道命令

特殊符号_cut命令

  • 任意个任意字符
    ? 任意一个字符
    “#” 注释字符
    \ 脱义字符
    | 管道符

cut命令截取字段的用法

[root@proxy124 ~]$ head -3 /etc/passwd | cut -c1-3     **#截取第一个到第三个字符**
roo
bin
dae
[root@proxy124 ~]$ 
[root@proxy124 ~]$ head -3 /etc/passwd | cut -d':' -f1    **#-d为分隔符,截取第一段**	
root
bin
daemon
[root@proxy124 ~]$ 
[root@proxy124 ~]$ head -3 /etc/passwd | cut -d':' -f1,2	**#-d为分隔符,截取第1和2段**
root:x
bin:x
daemon:x
[root@proxy124 ~]$ 
[root@proxy124 ~]$ head -3 /etc/passwd | cut --complement -d':' -f1,2	**#反选**
0:0:root:/root:/bin/bash
1:1:bin:/bin:/sbin/nologin
2:2:daemon:/sbin:/sbin/nologin
[root@proxy124 ~]$ 
[root@proxy124 ~]$ head -3 /etc/passwd | cut -b-2     **#打印前两个字节**
ro
bi
da
[root@proxy124 ~]$

sort_wc_uniq命令

[root@proxy124 shell3]$ awk '{print $1}' access.log | sort -n            #-n以阿拉伯数字排序,大-小,带有符号的内容默认为0,排在数字前面,不加-n以ASCII排序
10.203.67.45
10.203.75.64
10.204.51.97
[root@proxy124 shell3]$ 
[root@proxy124 shell3]$ awk '{print $1}' access.log | sort -nr		#-r倒序,-nr以阿拉伯数字倒序,小-大,带有符号的内容默认为0,排在数字后面
10.204.51.97
10.203.75.64
10.203.67.45
[root@proxy124 shell3]$ 
[root@proxy124 shell3]$ awk '{print $1}' access.log | sort -nr | uniq -c		#去除重复,并统计重复次数显示,不加-c只去重,不显示次数
      7 10.204.51.97
      1 10.203.75.64
      1 10.203.67.45
[root@proxy124 shell3]$ 

head /etc/passwd | sort -t ‘:’ -k3 #-t指定分隔符 -k3第三段排序
sort和uniq一定要结合使用,先排序后去重。

tee_tr_split命令

[root@proxy124 shell3]$ head -2 /etc/passwd | tee 1.txt    #标准正确输出到屏幕和文件1.txt,错误的输出不会到1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@proxy124 shell3]$ cat 1.txt 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@proxy124 shell3]$ 
[root@proxy124 shell3]$ echo "xuzhengmin" | tr '[xzm]' '[XZM]'		#替换字母
XuZhengMin
[root@proxy124 shell3]$ 

split -b 指定大小 file #表示切割成指定的大小,默认不带单位bytes
split -l 指定行数 file #表示切割成指定行数的文件

shell特殊符号

;#多条命令可以写到一行,用分号隔开
#用户家目录,正则表达式表示匹配符
&> #正确错误重定向
[] #指定[]中的一个。[0-9] [a-z] [abc] 还可用在判断上[ -d filename]
command1 || command2
command1执行成功则command2不执行
command2执行不成功则command执行
command1 && command2
command1执行成功则command2执行
command1执行不成功command2不执行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值