I could envision a simple shell script that would accomplish what I want by just iterating through a list of files in a directory and summing the individual size but was wondering if there was already a more concise way to do that.
something like
ls -lh *.jpg
that gives me the total size of just all the jpg files in the directory
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
The best Linux command to check file size is using du command. What we need is to open the terminal and type du -sh file name in the prompt. The file size will be listed on the first column. The size will be displayed in Human Readable Format.
How to view the file size of a directory. To view the file size of a directory pass the -s option to the du command followed by the folder. This will print a grand total size for the folder to standard output. Along with the -h option a human readable format is possible.
Try du
to summarize disk usage:
du -csh *.jpg
Output (for example):
8.0K sane-logo.jpg 16K sane-umax-advanced.jpg 28K sane-umax-histogram.jpg 24K sane-umax.jpg 16K sane-umax-standard.jpg 4.0K sane-umax-text2.jpg 4.0K sane-umax-text4.jpg 4.0K sane-umax-text.jpg 104K total
du
does not summarize the size of the files but summarizes the size of the used blocks in the file system. If a file has a size of 13K and the file system uses a block size of 4K, then 16K is shown for this file.
You can use this function :
dir () { ls -FaGl "${@}" | awk '{ last_size += $4; print }; END { print last_size }'; }
also you can use this command this is shorter and give you better result!
find YOUR_PATH -type f -name '*.jpg' -exec du -ch {} +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With