如何将索引节点数从最大到最小排序

问题描述 投票:0回答:1

我正在使用以下代码来显示索引节点和磁盘空间。它工作正常,但我想将计数从最大到最小排序。我需要进行哪些更改?

我试图添加sort | uniq -c | sort -rn,但是它不起作用。

for DIR in `find $CURDIR -maxdepth 1 -type d |grep -xv $CURDIR |sort`; do
    COUNT=$(GET_COUNT $DIR)
    SIZE=$(GET_SIZE $DIR)

    # Check if exclude arg was used, and if so only output directories above exclude inode count
    if [[ -z $exclude ]] || [[ -n $exclude && $COUNT -gt $exclude ]]
    then
        printf "$format" "  $COUNT" "  $SIZE" "`basename $DIR`"
    fi

我需要使索引节点和磁盘大小从最大到最小。

shell sorting inode
1个回答
0
投票

[而不是处理循环中的每个文件夹,请考虑结合使用'find ... -printf',并将其与适当的表达式组合以进行过滤(针对排除规则)

find $CURDIR -mindepth 1 -maxdepth 1 - type d -links +${exclude-0} -printf '%n %s %f\n'

如果

  • mindepth将排除顶层目录,
  • $ {exclude-0}将强制强制表达式为数字(如果未设置exclude,则导致'-links +0'。)
  • printf用于输出链接数,文件大小(字节)和基本文件名。
  • 例如:

exclude=2
find . -mindepth 1 -maxdepth 1 -type d  -links +${exclude+0} -printf '%n %s %f\n' 

Output:
3 4096 a
3 4096 b
© www.soinside.com 2019 - 2024. All rights reserved.