Submitted by Kirti Singh on 23/Apr/2020 11:45
Several times a Linux or Unix admin may need to get cumulative size of files based on certain parameter especially the file type.
In this example we are going to get cumulative size of *conf type files within a folder
Method 1 : This lets us take file size only in the current folder. It does not traverses the directory tree.
##################
sum=0;for i in `du -b *conf|tr -s '\t' ' '|cut -d ' ' -f1`; do sum=$((sum+i)); done; echo $sum
##################
Method 2 : Using this example we are able to traverse the directory tree.
##################
sum=0;for i in `find . -type f -name "*conf" -exec du -b {} \;|tr -s '\t' ' '| cut -d ' ' -f1`; do sum=$((sum+i)); done ; echo $sum
##################
For a video demonstration, please checkout the video below