![](/img/trans.png)
[英]How to list the files and folders in a directory with its total size in Linux?
[英]Calculate the total size of all files from a generated folders list with full PATH
我有一个包含多个目录和完整路径的列表:
/mnt/directory_1/sub_directory_1/
/mnt/directory_2/
/mnt/directory_3/sub_directory_3/other_directories_3/
我需要计算这个列表的总大小。
du -ch $file_list | tail -1 | cut -f 1
这是我能找到的最接近的答案,但给了我以下错误消息:
bash: /bin/du: 参数列表太长
不要使用反引号`。 改用$(..)
。
不使用:
command $(cat something)
这是一种常见的反模式。 它适用于简单的情况,失败更多,因为$(...)
的结果经历了分词和文件名扩展。
使用http://shellcheck.net检查您的脚本
如果您想“使用文件中的参数运行命令”,请使用xargs
或编写循环。 阅读https://mywiki.wooledge.org/BashFAQ/001 。 xargs
也会自己处理太多的 arguments。 而且我还会将-s
添加到du
。 尝试:
xargs -d'\n' du -sch < file_list.txt | tail -1 | cut -f 1
在repl bash上进行测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.