如何排序“查找”按大小在bash结果 [英] How to sort 'find' results in bash by size

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

问题描述

我想知道是否有一个简单的方式(通过管道或东西)订购(按文件大小)查找命令在bash的结果,如:

 查找/位置/的/目录/型的F -size + 2G


解决方案

您可以使用%K 例如打印的大小以KB为单位:

 找到。型的F -size + 2G -printf%KKB%P \\ N| -n排序


  • 将话说 -printf%KKB%P \\ N要打印千字节的文件,然后名称。

  • 排序-n 获取此输入,并相应进行排序。

见一个例子:

  $找到。型的F -size + 1M -printf%P%KKB \\ N|排序-n -k2
./arrr.txt.gz 1664KB
./brrr.gz 32388KB

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

解决方案

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

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

  • By saying -printf "%kKB %p\n" you are printing the file in kilobytes and then the name.
  • sort -n gets this input and sorts it accordingly.

See an example:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆