Linux sort命令详解

sort:帮我们依据不同的数据类型进行排序,其语法及常用参数格式:

     sort [-bcfMnrtk][源文件][-o 输出文件] 
            补充说明:sort可针对文本文件的内容,以行为单位来排序。        
        参  数:
          -b   忽略每行前面开始出的空格字符。
          -c   检查文件是否已经按照顺序排序。
          -f   排序时,忽略大小写字母。
          -M   将前面3个字母依照月份的缩写进行排序。
          -n   依照数值的大小排序。
          -o<输出文件>   将排序后的结果存入指定的文件。
          -r   以相反的顺序来排序。
          -t<分隔字符>   指定排序时所用的栏位分隔字符。
          -k  选择以哪个区间进行排序。

  

[root@localhost ~]# last|grep '192'|awk '{S[$3]++} END{for(a in S) {print a,S[a]}}'|sort -rn  

image

[root@localhost ~]# last|grep '192'|awk '{S[$3]++} END{for(a in S) {print a,S[a]}}'|sort -o /home/omc/sort.txt
[root@localhost ~]# ll /home/omc/sort.txt 
      -rw-r--r--. 1 root root 69 Jun 25 17:25 /home/omc/sort.txt

image

 

超常用的命令: 按照文件大小倒叙显示

[root@localhost omc]# du -sh * | sort -h  

 

posted @ 2018-06-26 08:30  小a玖拾柒  阅读(11116)  评论(0编辑  收藏  举报