du -sh is one of the common ways which I utilize du command, I used it to get the total disk size of current directory occupied. Another one is du -hd1, getting the disk sizes of each subdirectory uses, it lists one by one instead of a grand amount.
But how about the total sizes of individual files which you are interested? Not indented to show off my AWK scripting skill, but I did use AEK to sum it up byte counts from find or ls command if it’s too complicated, i.e. involving some directories. To be honest, that shows no skill at all, 10-minute AWK noob can do that and only reveals how I was unfamiliar with du command and clearly I didn’t RTFM. From its manpage:
-c, --total | produce a grand total |
It’s as simply as that and I didn’t even know before. So, basically, you can do:
find -L -name 'PATTERN' -print0 | du -ch --files0-from -
Or simply, if filenames do not contain spaces:
du -ch $(find -L -name 'PATTERN' -print0)
That’s all you need, although you still need some knowledge of find. The -L is for symbolic link (symlink), you can ignore/omit that if you don’t even know what it is, you probably don’t need that. For files in current directory, you can use it as if it’s a ls command, for example:
du -ch *.txt
That’s all.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.