shell - 如何将inode计数从大到小排序
问题描述
我使用下面的代码来显示 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 和磁盘大小计数。
解决方案
不是在循环中处理每个文件夹,而是考虑结合利用“find ... -printf”,将其与适当的表达式结合起来进行过滤(用于排除规则)
find $CURDIR -mindepth 1 -maxdepth 1 - type d -links +${exclude-0} -printf '%n %s %f\n'
在哪里
- mindepth 将排除顶层目录,
- ${exclude-0} 将强制表达式为数字(如果未设置排除,则导致'-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
推荐阅读
- python - 如何从火花数据框中提取 csv 名称
- outlook - Outlook 中的对话/线程/帖子有什么区别?
- haskell - 是否可以通过 GHC 的通用派生来派生 Data.Vector.Unbox ?
- angular - Typescript getter/setter 命名约定
- ms-access - 访问减数的表达式
- django - 关闭时间过长被杀
- python - 重命名熊猫中的选定列
- javascript - => Angularjs。对于传入的值,我是否正确理解这一点?
- javascript - 在 ChromeDevTools-GUI 中更改 Sources --> Scope --> Local 中的变量值
- angular - 如何对 mat-autocomplete 选项的选择进行单元测试?