linux sort命令的重要用法:按分隔符/字母/数字/月份进行排序
2023-02-18 16:30:55 时间
1.指定分隔符,以某一列进行排序并输出
#-t 指定一个分隔符
#-k 后面跟数字,指定按第几列进行排序
#-r 反序排序(升序变成降序)
#按“:”做分隔符,以第3列,也就是用户UID,来从大到小排序
[root@node5 opt]# sort -t ":" -nk3 -r /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
putong:x:8004:8004::/home/putong:/bin/bash
www:x:8003:8003::/home/www:/bin/bash
stick:x:8002:8002::/home/stick:/bin/bash
esnode:x:8001:8001::/home/esnode:/bin/bash
......
2.输出内容按字母规则进行排序
#默认按字母规则进行排序
[root@node5 opt]# cat /etc/group | sort
adm:x:4:
apache:x:48:
audio:x:63:
bin:x:1:
cdrom:x:11:
daemon:x:2:
......
3.输出内容按数字大小进行排序
[root@node5 opt]# cat num.txt
21
456
9789
234
24
11
1
31
32
1
3
31
#-n 数字从小到大排序
[root@node5 opt]# cat num.txt | sort -n
1
1
3
11
21
24
31
31
32
234
456
9789
#数字从大到小排序
[root@node5 opt]# sort -r num.txt
9789
456
32
31
31
3
24
234
21
11
1
1
4.输出内容按月份进行排序
[root@node5 opt]# cat month.txt
December
October
January
November
July
April
February
March
August
May
September
June
#-M 按月份进行排序
[root@node5 opt]# sort -M month.txt
January
February
March
April
May
June
July
August
September
October
November
December
5.指定目录下的文件按大小进行排序
#把etc目录下所有的文件,按从大到小排序
[root@node5 ~]# du -h /etc | sort -nr
相关文章
- [Go] 申请成功软件著作权了😎✌!-GOFLY在线客服系统
- [Go] 解决packets.go:36: read tcp 127.0.0.1:51139->127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host ma chine.
- [Go] go run 时 os.Getwd 和 os.Executable 获取程序根路径
- [Go]go.mod 文件中的// indirect意思代表间接依赖
- [Go] 解决 imported from implicitly required module
- [Go] go语言中的结构体标签
- [Go] go语言使用dgrijalva/jwt-go 实现加解密jwt
- [Go] go语言gin框架验证post传递json数据
- [Go] go语言gin框架封装返回的错误码类
- [Go] go语言中使用方法声明给类定义方法
- [Linux] ubuntu系统多PHP版本切换
- [git] 查看两个分支的差异
- [git] git清理远端已删除分支在本地的备份
- [git] Git Clean 清除 untrack 没有加入版本库的文件
- [linux] ab压测工具进行post压力测试
- [Go]golang中的urlencode和urldecode
- [linux] du查找数据大的目录
- [Go] golang获取程序执行的绝对路径
- [linux] 查看centos或ubuntu的系统版本
- [linux] centos系统yum安装rz与sz