简体   繁体   English

Linux:查找文件中文件路径的总文件大小

[英]Linux: Find total filesize of files path inside a file

I have a file containing some file paths like: 我有一个包含一些文件路径的文件,如:

./file1
./dir/file2
./dir3/dir4/fil3
etc

How can i find the total filesize of all of them? 我怎样才能找到所有这些文件的总文件大小? I know about "du" for getting the filesize of single file but no idea how to use a file. 我知道“du”获取单个文件的文件大小但不知道如何使用文件。

Thank you 谢谢

you can use du to give total size of multiple files 您可以使用du来提供多个文件的总大小

 cat file | tr "\n" "\0" | du -ch --files0-from=- | tail -n1

Use awk for getting file size 使用awk获取文件大小

 cat file | awk  '{system("ls -l " $0)}' | awk '{ TOTAL += $5} END { print TOTAL}'

GNU coreutils du only suggestion GNU coreutils du only建议

EDIT: the named option --files0-from is a GNU extension, so this suggested solution won't work with any non GNU coreutils du version. 编辑:命名选项--files0-from是一个GNU扩展,所以这个建议的解决方案不适用于任何非GNU coreutils du版本。 As you don't semm to have it the awk version posted by Vivek Goel is the one you should try instead. 因为你不喜欢它,所以你应该尝试使用Vivek Goel发布的awk版本。

You already answered your own question. 你已经回答了自己的问题。 Using du is the key. 使用du是关键。 The "missing" option you're looking for might be this one found in the manual pages. 您正在寻找的“缺失”选项可能是手册页中的这个选项。 (man du) (man du)

--files0-from=F --files0-从= F
summarize disk usage of the NUL-terminated file names specified in file F; 总结文件F中指定的NUL终止文件名的磁盘使用情况; If F is - then read names from standard input 如果F是 - 则从标准输入读取名称

Usage would be like this: 用法如下:

tr "\n" "\0" <file-list | du --files0-from=- 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM