如何使用“tree”命令行工具从最小到最大排序?

如何使用“tree”命令行工具从最小到最大排序?

命令行工具应使用哪个选项tree来从最大到最小排序?

├── [4.0K]  types2
│   └── [ 116]  types2.go
├── [4.0K]  types3
│   ├── [ 689]  types3.go
│   └── [   0]  types3.go~
├── [4.0K]  web
│   ├── [ 149]  index.html
│   ├── [ 647]  web.go
│   └── [   0]  web.go~
├── [4.0K]  wordcount
│   ├── [ 996]  wordcount.go
│   └── [ 773]  wordcount.go~
└── [4.0K]  zero
   ├── [  97]  zero.go
   └── [5.8K]  zero.o

答案1

即使树工具不支持直接按大小排序,您仍然可以使用种类。

您可以使用以下命令列出给定文件夹和子文件夹中的所有文件及其路径及其文件大小,然后使用种类按第二列对它们进行排序的工具输出(即这些大小,是所有的第一列[符号)。我们用grep此处仅过滤具有给定扩展名的文件。

这是命令:

tree -sifF /opt/aplicaciones/gio/ | grep -v '/$' | grep ".jar"  | sort -k2 -rn

下面是一个包含大量文件的示例输出,以便您可以了解其行为方式:

[   89702805]  /myapp/first_folder/artifact/this-is-a-file-number-1.jar
[   89511250]  /myapp/first_folder/artifact/this-is-a-file-number-2_22_11_2022.jar
[   89508457]  /myapp/first_folder/artifact/this-is-a-file-number-2.jar
[   89487284]  /myapp/first_folder/artifact/this-is-a-file-number-2_backup.jar
[   73631126]  /myapp/first_folder/artifact/this-is-a-file-number-3.jar
[   73416714]  /myapp/first_folder/artifact/this-is-a-file-number-4.jar
[   72904056]  /myapp/second_folder/artifact/this-is-a-file-number-5.jar
[   72870839]  /myapp/second_folder/artifact/this-is-a-file-number-6.jar
[   72824807]  /myapp/second_folder/artifact/this-is-a-file-number-7.jar
[   72822778]  /myapp/second_folder/artifact/this-is-a-file-number-8.jar
[   72822392]  /myapp/second_folder/artifact/this-is-a-file-number-9.jar
[   72822125]  /myapp/second_folder/artifact/this-is-a-file-number-10.jar
[   72821288]  /myapp/second_folder/artifact/this-is-a-file-number-11.jar
[   72808348]  /myapp/first_folder/artifact/this-is-a-file-number-12.jar
[   72794504]  /myapp/second_folder/artifact/this-is-a-file-number-13.jar
[   70309496]  /myapp/first_folder/artifact/this-is-a-file-number-14.jar
[   70298847]  /myapp/first_folder/artifact/this-is-a-file-number-15.jar
[   70286111]  /myapp/first_folder/artifact/this-is-a-file-number-16.jar
[   70283872]  /myapp/first_folder/artifact/this-is-a-file-number-17.jar
[   70281102]  /myapp/first_folder/artifact/this-is-a-file-number-18.jar
[   70275702]  /myapp/first_folder/artifact/this-is-a-file-number-19.jar
[   70274483]  /myapp/first_folder/artifact/this-is-a-file-number-20.jar
[   70273588]  /myapp/first_folder/artifact/this-is-a-file-number-21.jar
[   70273058]  /myapp/first_folder/artifact/this-is-a-file-number-22.jar
[   70271031]  /myapp/first_folder/artifact/this-is-a-file-number-23.jar
[   70265460]  /myapp/first_folder/artifact/this-is-a-file-number-24.jar
[   70090818]  /myapp/first_folder/artifact/this-is-a-file-number-25.jar
[   69510384]  /myapp/first_folder/artifact/this-is-a-file-number-26.jar
[   68674140]  /myapp/first_folder/artifact/this-is-a-file-number-27.jar
[   68367619]  /myapp/second_folder/artifact/this-is-a-file-number-28.jar
[   65897101]  /myapp/first_folder/artifact/this-is-a-file-number-29.jar
[   65011678]  /myapp/first_folder/artifact/this-is-a-file-number-30.jar
[   65010373]  /myapp/second_folder/artifact/this-is-a-file-number-31.jar
[   51954261]  /myapp/second_folder/artifact/this-is-a-file-number-32__test.jar
[   48092911]  /myapp/second_folder/artifact/this-is-a-file-number-32.jar
[   43081254]  /myapp/second_folder/artifact/this-is-a-file-number-33.jar
[   23357588]  /myapp/third_folder/artifact/this-is-a-file-number-34.jarA
[   23357588]  /myapp/third_folder/artifact/this-is-a-file-number-34.jar

现在,对所使用的选项进行解释:

从男人身上,大约

  • -s打印每个文件的大小(以字节为单位)以及名称。
  • -我使树不打印缩进线,与 -f 选项结合使用时很有用。
  • -F打印每个文件的完整路径前缀。
  • -F为目录附加“/”,为套接字文件附加“=”,为可执行文件附加“*”,为可执行文件附加“|”对于 FIFO,按照 ls -F

关于种类

  • -k--key=POS1[,POS2] 在 POS1(起始点 1)处开始一个键,在 POS2 处结束(默认行尾)即只需将其视为由空格分隔的列即可。
  • -r--reverse 反转比较结果
  • -n--numeric-sort 根据字符串数值进行比较

答案2

树效用目前不支持按大小排序。

相关内容