2016年11月13日日曜日

calculate total file size.

Sum up file size for specific type of files.

 $ find ./<directory_name>  -print | grep -E  "mp4$|wmv$|avi$|jpg$|png$|mp3$|mkv" | awk '{print "ls  -l \""$0"\""}' > <tmporary_file_name>

The content of size_t_file is as below

ls -l "./<directory_name>/<subdirectory_name>/001.jpg"
ls -l "./<directory_name>/<subdirectory_name>/002.jpg"

Then

$ sh <tmporary_file_name> | awk '{total = total + $5}END{print "total is "total}'

This will count all designated type's file size and calculate the summation.

$find ./<directory_name>  -print | grep -vE  "mp4$|wmv$|avi$|jpg$|png$|mp3$|mkv$|JPG$|MP4$|AVI$"

The command above will omit all output which ends with motion and still picture file type. Use option "-v" for this purpose.