Warm tip: This article is reproduced from serverfault.com, please click

pipe-Bash获取通过head命令提取的文件列表的大小

(pipe - Bash get size of a list of files extracted with head command)

发布于 2020-12-02 19:48:41

我有以下bash命令,该命令为我提供了一个文件夹的300个随机文件。

ls / directory / | 排序-R | 头-n 300

我想像这样获得300个随机文件的总大小

ls / directory / | 排序-R | 头-n 300 | 杜-h

问题是,“ du”不是针对这300个文件执行的,而是针对我当前所在的整个目录执行的。

我该怎么做?

Questioner
Petar Yakov
Viewed
11
Timur Shtatland 2020-12-03 04:16:10

使用findxargs像这样:

find /directory -mindepth 1 -maxdepth 1 | sort -R | head -n300 | xargs du -sh

要同时打印所有要xargs馈入的文件的总大小,请du中添加-c选项du,如下所示:du -sch