How to calculate the total size of certain files only, recursive, in linux

后端 未结 3 1899
攒了一身酷
攒了一身酷 2020-12-29 12:27

I\'ve got a bunch of files scattered across folders in a layout, e.g.:

dir1/somefile.gif
dir1/another.mp4
dir2/video/filename.mp4
dir2/some.file
dir2/blahbla         


        
3条回答
  •  无人及你
    2020-12-29 12:45

    You can simply do :

    find -name "*.mp4" -exec du -b {} \; | awk 'BEGIN{total=0}{total=total+$1}END{print total}'
    

    The -exec option of find command executes a simple command with {} as the file found by find. du -b displays the size of the file in bytes. The awk command initializes a variable at 0 and get the size of each file to display the total at the end of the command.

提交回复
热议问题