linux sort 命令
Posted 王先生架构
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux sort 命令相关的知识,希望对你有一定的参考价值。
[[email protected] /]# sort 排序^C [[email protected] /]# sort /etc/passwd adm:x:3:4:adm:/var/adm:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin haldaemon:x:68:68:HAL daemon:/:/sbin/nologin halt:x:7:0:halt:/sbin:/sbin/halt lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin mail:x:8:12:mail:/var/spool/mail:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin root:x:0:0:root:/root:/bin/bash rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin wanghaipeng:x:501:502::/home/wanghaipeng:/bin/bash whp:x:500:501::/home/whp:/bin/bash [[email protected] /]# sort -t: -k3 /etc/passwd root:x:0:0:root:/root:/bin/bash uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin whp:x:500:501::/home/whp:/bin/bash wanghaipeng:x:501:502::/home/wanghaipeng:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin haldaemon:x:68:68:HAL daemon:/:/sbin/nologin vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin halt:x:7:0:halt:/sbin:/sbin/halt sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin mail:x:8:12:mail:/var/spool/mail:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin [[email protected] /]# sort -t: -k3 /etc/passwd 段排序 冒号分割 第三段^C [[email protected] /]# sort -t: -k3,5 -n /etc/passwd 区间排序^C [[email protected] /]# sort -t: -k3 -n -r /etc/passwd 倒序^C [[email protected] /]# touch 2.txt [[email protected] /]# vim 2.txt [[email protected] /]# sort 2.txt 1 2 3 4 5 6 a dsf sdfsf [[email protected] /]# sort -n -r 2.txt 6 5 4 3 2 1 sdfsf dsf a [[email protected] /]# sort -u 2.txt ^C [[email protected] /]# sort -u 2.txt ^C sort: 获取文件状态失败(stat): ^C: 没有那个文件或目录 [[email protected] /]# sort -u 2.txt 排序 去重复^C [[email protected] /]# vim 2.txt [[email protected] /]# sort -un 2.txt sdfsf 1 2 3 4 5 6 [[email protected] /]# cat 2.txt 1 2 3 4 5 6 sdfsf a dsf 1 2 3 a sd [[email protected] /]#
以上是关于linux sort 命令的主要内容,如果未能解决你的问题,请参考以下文章