total size of group of files selected with 'find'

后端 未结 7 1924
庸人自扰
庸人自扰 2020-12-07 16:32

For instance, I have a large filesystem that is filling up faster than I expected. So I look for what\'s being added:

find /rapidly_shrinking_drive/ -type f          


        
7条回答
  •  鱼传尺愫
    2020-12-07 17:06

    Recently i faced the same(almost) problem and i came up with this solution.

    find $path -type f -printf '%s '
    

    It'll show files sizes in bytes, from man find:

    -printf format
        True; print format on the standard output, interpreting `\' escapes and `%' directives.  Field widths and precisions can be spec‐
        ified as with the `printf' C function.  Please note that many of the fields are printed as %s rather than %d, and this  may  mean
        that  flags  don't  work as you might expect.  This also means that the `-' flag does work (it forces fields to be left-aligned).
        Unlike -print, -printf does not add a newline at the end of the string.
        ...
        %s  File's size in bytes.
        ...
    

    And to get a total i used this:

    echo $[ $(find $path -type f -printf %s+)0] #b
    echo $[($(find $path -type f -printf %s+)0)/1024] #Kb
    echo $[($(find $path -type f -printf %s+)0)/1024/1024] #Mb
    echo $[($(find $path -type f -printf %s+)0)/1024/1024/1024] #Gb
    

提交回复
热议问题