【发布时间】:2021-09-01 11:31:45
【问题描述】:
我正在使用以下 find 命令递归地列出文件夹中的所有文件并按大小对其进行排序(最大大小在顶部)
find . -not -path '*/\.*' -not -name '*.nfo' -type f -exec du -h {} + | sort -r -h
该命令运行良好,但我需要从每个结果中删除完整路径,仅保留文件名
例如。
Dir/AnotherDir/file.mp4 should be listed as file.mp4
通常当我必须在 find 命令中执行此操作时,我只需使用 -printf '%f\n' 但这不能在我当前的命令中使用,因为文件正在由 du 命令打印
【问题讨论】:
-
basename:打印 NAME 并删除所有前导目录组件
-
我知道这个命令,但它如何与 du 命令一起使用?
-
或将输出通过管道传送到 sed:
... | sed -e 's@.*/@@'