本文介绍了如何按大小对bash中的“查找"结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种简单"的方式(通过管道或其他方式)来排序(按文件大小)bash 中查找"命令的结果,例如:

I am wondering if there's an "easy" way (through a pipe or something) to order (by file size) the results of a "find" command in bash such as:

find /location/of/directory/ -type f -size +2G

推荐答案

您可以使用 %k 例如以千字节为单位打印大小:

You can use %k for example to print the size in kilobytes:

find . -type f -size +2G -printf "%kKB %p
" | sort -n

  • 通过说 -printf "%kKB %p",您正在以千字节为单位打印文件,然后是名称.
  • sort -n 获取此输入并相应地对其进行排序.
    • By saying -printf "%kKB %p" you are printing the file in kilobytes and then the name.
    • sort -n gets this input and sorts it accordingly.
    • 看一个例子:

      $ find . -type f -size +1M -printf "%p %kKB
      " | sort -n -k2
      ./arrr.txt.gz 1664KB
      ./brrr.gz 32388KB
      

      这篇关于如何按大小对bash中的“查找"结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 03:24