【发布时间】:2020-01-30 00:43:40
【问题描述】:
我使用下面的代码来显示 inode 和磁盘空间。它工作正常,但我想从最大到最小对计数进行排序。我需要做哪些改变?
我尝试添加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
我需要从最大到最小的 inode 和磁盘大小计数。
【问题讨论】:
-
“它不工作”是什么意思?如果您有未排序的数据并将其通过管道传输到
sort,它将被排序。鉴于您没有展示GET_COUNT或GET_SIZE做了什么,或者您当前的输出是什么,也没有说明您为什么不只是使用df,很难说为什么您不能只将您的数据通过管道传输到sort. -
github.com/tripflex/inodes/blob/master/inodes 我正在使用这个 bash 脚本。但是当我尝试添加 uniq -c | sort -rn 在现有脚本中,我得到如下错误: du: cannot access ‘ 1 /home/new/cache': No such file or directory