学习linux第二十六天

cut

[root@hanlin ~]$cat /etc/passwd |head -n 2 |cut -d ":" -f 1-3 (cut分割,-d指定分割符号。-f 指定截取哪几列)
root:x:0
bin:x:1

 

sort

[root@hanlin lvm]# sort 1.txt (对1.txt进行排序,默认按照ASCII码来排序。特殊符号>数字>字母)
;
.
[
}
0
123
1233
1234
12a3
22222;\33333
22222\33333
222333444444
43
adds
assss
btju
dver
ff
fhenf
rgt5r3
s
vxsb
wqfwqf

 

[root@hanlin lvm]# sort -n \1.txt  (-n表示按照数字从小到大来排序其他的都算0排在上面 -r反序进行排列)
;
.
[
}
0
adds
assss
btju
dver
ff
fhenf
rgt5r3
s
vxsb
wqfwqf
yy
12a3
43
123
1233
1234
22222;\33333
22222\33333
222333444444

wc (统计)

[root@hanlin lvm]# wc -l 1.txt (统计行数)
24 1.txt

 

[root@hanlin lvm]# wc -m 1.txt (统计字符数,默认在现有行数的基础上再加上行数,因为每一行结尾有一个换行符)

126 1.txt

 

[root@hanlin lvm]# wc -w 1.txt  (统计词数,特殊字符,空格,什么的都会把内容区分成一个个词,要求连续的才行)
24 1.txt

uniq (去重)

[root@hanlin lvm]# uniq q.txt (单独去重,只去掉相邻的重复内容,要加上sort效果才会体现出来)
123
wer
234
123
1
2
999
444
6
[root@hanlin lvm]# cat q.txt
123
wer
234
123
1
1
2
2
2
2
999
444
6

[root@hanlin ~]# sort 1.txt |uniq (排序内容并且去除重复行)
<
>
|
,
{
111
222
33333333
4567453654
gdsfg
gsag
gsdahgbnfgh
hdfgxh
te4wt
trsetas
yerwy
yhrsfdty
[root@hanlin ~]# sort 1.txt |uniq -c (排序去重。并且统计重复行的行数 -c统计行数)

1 
1 <
1 >
1 |
1 ,
1 {
2 111
2 222
1 33333333
1 4567453654
1 gdsfg
1 gsag
1 gsdahgbnfgh
1 hdfgxh
1 te4wt
1 trsetas
1 yerwy
1 yhrsfdty

tee  追加并打印
[root@hanlin ~]# sort 1.txt |uniq -c > qq.txt (重定向前面的结果到qq.txt中,不能显示出来)
[root@hanlin ~]# sort 1.txt |uniq -c |tee qq.txt (重定向前面的内容到qq.txt中,并且打印在屏幕中)

1 <
1 >
1 |
1 ,
1 {
2 111
2 222
1 33333333
1 4567453654
1 gdsfg
1 gsag
1 gsdahgbnfgh
1 hdfgxh
1 te4wt

1 trsetas
1 yerwy
1 yhrsfdty

[root@hanlin ~]# > qq.txt (把空的内容重定向到文本,相当于是清空文本内容)

[root@hanlin ~]# echo '111111' |tee -a qq.txt (表示追加内容到qq.txt,并且把追加的内容打印在屏幕上)
111111
tr  替换字符

[root@hanlin ~]# echo "hanlin" |tr 'a' 'A'
hAnlin
[root@hanlin ~]# echo "hanlin" |tr 'a-z' 'A-Z'
HANLIN
[root@hanlin ~]# echo "hanlin" |tr 'a-z' '1'
111111

 

split 切割文件分成若干等分大小的小文件,命名以xaa开始,往下递增,到四位的时候命名为xzaa开始递增

[root@hanlin lvm]# du -sh 1.txt
3.6M 1.txt
[root@hanlin lvm]# man split
[root@hanlin lvm]# split -b 1M 1.txt (切割1.txt为若干1m的小文件)
[root@hanlin lvm]# ls
1.txt xaa xab xac
[root@hanlin lvm]# split -b 1M 1.txt xy (指定文件名的前缀)
[root@hanlin lvm]# ls
1.txt xyaa xyab xyac

 

特殊符号

$               变量前缀 

!$            正则里面表示行尾

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

~                用户家目录,正则表示匹配符

&                放在命令后面,表示把命令放在后台

>                覆盖正确命令的输出

>>             追加正确命令的输出

2>             覆盖错误命令的输出

2>>           追加错误命令的输出

&>             不管命令是否正确都输出

[]               指定字符中的一个 比如[a-z] [1-9]

||                只执行一个命令,从前往后排队,只要有一个能输出就结束

[root@hanlin lvm]# ls
1.txt

[root@hanlin lvm]# ls -l la.txt || wc -l 1.txt
ls: 无法访问la.txt: 没有那个文件或目录
72968 1.txt
[root@hanlin lvm]# ls -l 1.txt || wc -l 1.txt
-rw-r--r-T. 1 root root 2578388 6月 9 13:10 1.txt
&&              前面的命令错误就终止,正确的话继续执行 

[root@hanlin lvm]# ls -l 1.txt && wc -l 1.txt
-rw-r--r-T. 1 root root 2578388 6月 9 13:10 1.txt
72968 1.txt
[root@hanlin lvm]# ls -l ls.txt && wc -l 1.txt
ls: 无法访问ls.txt: 没有那个文件或目录

 

[root@hanlin lvm]# [-d xy] || mkdir xy (判断路径下有没有xy目录如果没有则创建此目录)
bash: [-d: 未找到命令...
[root@hanlin lvm]# ls
1.txt xy

转载于:https://my.oschina.net/u/3867255/blog/1839018

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值