How can I know the total size taken by specific kind of files in my hard drive?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












4















I would like to know if there's a command that can tell me how much storage are the .jpg files (for example). Something like if I do find / -iname "*.jpg" which can add the size of each file found and output a total.










share|improve this question
























  • Output the find results in a file an run du -s on its content.

    – Julie Pelletier
    Jul 2 '16 at 20:05















4















I would like to know if there's a command that can tell me how much storage are the .jpg files (for example). Something like if I do find / -iname "*.jpg" which can add the size of each file found and output a total.










share|improve this question
























  • Output the find results in a file an run du -s on its content.

    – Julie Pelletier
    Jul 2 '16 at 20:05













4












4








4


2






I would like to know if there's a command that can tell me how much storage are the .jpg files (for example). Something like if I do find / -iname "*.jpg" which can add the size of each file found and output a total.










share|improve this question
















I would like to know if there's a command that can tell me how much storage are the .jpg files (for example). Something like if I do find / -iname "*.jpg" which can add the size of each file found and output a total.







find disk-usage images






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 11 at 20:21









Rui F Ribeiro

41.1k1480138




41.1k1480138










asked Jul 2 '16 at 20:03









VaToVaTo

1,8821832




1,8821832












  • Output the find results in a file an run du -s on its content.

    – Julie Pelletier
    Jul 2 '16 at 20:05

















  • Output the find results in a file an run du -s on its content.

    – Julie Pelletier
    Jul 2 '16 at 20:05
















Output the find results in a file an run du -s on its content.

– Julie Pelletier
Jul 2 '16 at 20:05





Output the find results in a file an run du -s on its content.

– Julie Pelletier
Jul 2 '16 at 20:05










2 Answers
2






active

oldest

votes


















5














find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch +


Or much faster



find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-


Or simply,



du -ch /path/to/your/drive/*.jpg | grep total


Or with help of awk,



find /path/to/your/drive -iname "*.jpg" -ls | awk 'total += $7 END print total'


On my system file size shows on seventh field, if it's different for you then adjust accordingly.



As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)



 find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc


Or



 du -shc $(find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' | cut -d':' -f1) | grep total





share|improve this answer




















  • 1





    That will only give the individual sizes of each file.

    – Julie Pelletier
    Jul 2 '16 at 20:17











  • @julipelletier typo corrected

    – Rahul
    Jul 2 '16 at 20:19











  • Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

    – VaTo
    Jul 2 '16 at 20:39







  • 2





    @Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

    – Stéphane Chazelas
    Jul 2 '16 at 20:46











  • @Saul see updated answer

    – Rahul
    Jul 2 '16 at 21:08


















2














As an alternative, you can do this using only POSIX:



find . -type f -name "*.jpg" -exec du -sk ; |
awk 'BEGINtotal=0;total += $1; ENDprintf "%.3f MBn", total / 1024'


Further reading:




  • du - estimate file space usage (POSIX)


  • find - find files (POSIX)





share|improve this answer

























  • (about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

    – Stéphane Chazelas
    Jul 2 '16 at 20:58











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f293499%2fhow-can-i-know-the-total-size-taken-by-specific-kind-of-files-in-my-hard-drive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch +


Or much faster



find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-


Or simply,



du -ch /path/to/your/drive/*.jpg | grep total


Or with help of awk,



find /path/to/your/drive -iname "*.jpg" -ls | awk 'total += $7 END print total'


On my system file size shows on seventh field, if it's different for you then adjust accordingly.



As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)



 find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc


Or



 du -shc $(find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' | cut -d':' -f1) | grep total





share|improve this answer




















  • 1





    That will only give the individual sizes of each file.

    – Julie Pelletier
    Jul 2 '16 at 20:17











  • @julipelletier typo corrected

    – Rahul
    Jul 2 '16 at 20:19











  • Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

    – VaTo
    Jul 2 '16 at 20:39







  • 2





    @Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

    – Stéphane Chazelas
    Jul 2 '16 at 20:46











  • @Saul see updated answer

    – Rahul
    Jul 2 '16 at 21:08















5














find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch +


Or much faster



find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-


Or simply,



du -ch /path/to/your/drive/*.jpg | grep total


Or with help of awk,



find /path/to/your/drive -iname "*.jpg" -ls | awk 'total += $7 END print total'


On my system file size shows on seventh field, if it's different for you then adjust accordingly.



As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)



 find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc


Or



 du -shc $(find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' | cut -d':' -f1) | grep total





share|improve this answer




















  • 1





    That will only give the individual sizes of each file.

    – Julie Pelletier
    Jul 2 '16 at 20:17











  • @julipelletier typo corrected

    – Rahul
    Jul 2 '16 at 20:19











  • Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

    – VaTo
    Jul 2 '16 at 20:39







  • 2





    @Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

    – Stéphane Chazelas
    Jul 2 '16 at 20:46











  • @Saul see updated answer

    – Rahul
    Jul 2 '16 at 21:08













5












5








5







find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch +


Or much faster



find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-


Or simply,



du -ch /path/to/your/drive/*.jpg | grep total


Or with help of awk,



find /path/to/your/drive -iname "*.jpg" -ls | awk 'total += $7 END print total'


On my system file size shows on seventh field, if it's different for you then adjust accordingly.



As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)



 find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc


Or



 du -shc $(find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' | cut -d':' -f1) | grep total





share|improve this answer















find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch +


Or much faster



find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-


Or simply,



du -ch /path/to/your/drive/*.jpg | grep total


Or with help of awk,



find /path/to/your/drive -iname "*.jpg" -ls | awk 'total += $7 END print total'


On my system file size shows on seventh field, if it's different for you then adjust accordingly.



As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)



 find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc


Or



 du -shc $(find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' | cut -d':' -f1) | grep total






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 2 '16 at 21:07

























answered Jul 2 '16 at 20:10









RahulRahul

9,28212844




9,28212844







  • 1





    That will only give the individual sizes of each file.

    – Julie Pelletier
    Jul 2 '16 at 20:17











  • @julipelletier typo corrected

    – Rahul
    Jul 2 '16 at 20:19











  • Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

    – VaTo
    Jul 2 '16 at 20:39







  • 2





    @Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

    – Stéphane Chazelas
    Jul 2 '16 at 20:46











  • @Saul see updated answer

    – Rahul
    Jul 2 '16 at 21:08












  • 1





    That will only give the individual sizes of each file.

    – Julie Pelletier
    Jul 2 '16 at 20:17











  • @julipelletier typo corrected

    – Rahul
    Jul 2 '16 at 20:19











  • Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

    – VaTo
    Jul 2 '16 at 20:39







  • 2





    @Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

    – Stéphane Chazelas
    Jul 2 '16 at 20:46











  • @Saul see updated answer

    – Rahul
    Jul 2 '16 at 21:08







1




1





That will only give the individual sizes of each file.

– Julie Pelletier
Jul 2 '16 at 20:17





That will only give the individual sizes of each file.

– Julie Pelletier
Jul 2 '16 at 20:17













@julipelletier typo corrected

– Rahul
Jul 2 '16 at 20:19





@julipelletier typo corrected

– Rahul
Jul 2 '16 at 20:19













Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

– VaTo
Jul 2 '16 at 20:39






Thank you Rahul, I just wonder how can I make it work with: find . -name '*' -exec file ; | grep -o -P '^.+: w+ image' which basically looks for all images not just jp*g files.

– VaTo
Jul 2 '16 at 20:39





2




2





@Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

– Stéphane Chazelas
Jul 2 '16 at 20:46





@Saul, find . -type f -exec file --mime-type + | sed -n 's|: image/[^[:blank:]]*$||p' | tr 'n' '' | du --files0-from=- -hc

– Stéphane Chazelas
Jul 2 '16 at 20:46













@Saul see updated answer

– Rahul
Jul 2 '16 at 21:08





@Saul see updated answer

– Rahul
Jul 2 '16 at 21:08













2














As an alternative, you can do this using only POSIX:



find . -type f -name "*.jpg" -exec du -sk ; |
awk 'BEGINtotal=0;total += $1; ENDprintf "%.3f MBn", total / 1024'


Further reading:




  • du - estimate file space usage (POSIX)


  • find - find files (POSIX)





share|improve this answer

























  • (about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

    – Stéphane Chazelas
    Jul 2 '16 at 20:58
















2














As an alternative, you can do this using only POSIX:



find . -type f -name "*.jpg" -exec du -sk ; |
awk 'BEGINtotal=0;total += $1; ENDprintf "%.3f MBn", total / 1024'


Further reading:




  • du - estimate file space usage (POSIX)


  • find - find files (POSIX)





share|improve this answer

























  • (about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

    – Stéphane Chazelas
    Jul 2 '16 at 20:58














2












2








2







As an alternative, you can do this using only POSIX:



find . -type f -name "*.jpg" -exec du -sk ; |
awk 'BEGINtotal=0;total += $1; ENDprintf "%.3f MBn", total / 1024'


Further reading:




  • du - estimate file space usage (POSIX)


  • find - find files (POSIX)





share|improve this answer















As an alternative, you can do this using only POSIX:



find . -type f -name "*.jpg" -exec du -sk ; |
awk 'BEGINtotal=0;total += $1; ENDprintf "%.3f MBn", total / 1024'


Further reading:




  • du - estimate file space usage (POSIX)


  • find - find files (POSIX)






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 2 '16 at 20:53

























answered Jul 2 '16 at 20:43









Thomas DickeyThomas Dickey

53.8k5103176




53.8k5103176












  • (about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

    – Stéphane Chazelas
    Jul 2 '16 at 20:58


















  • (about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

    – Stéphane Chazelas
    Jul 2 '16 at 20:58

















(about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

– Stéphane Chazelas
Jul 2 '16 at 20:58






(about ;) That's a POSIX requirement. I tried to have that requirement lifted as I couldn't find any implementation where it was needed, but that was rejected by the gawk maintainer.

– Stéphane Chazelas
Jul 2 '16 at 20:58


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f293499%2fhow-can-i-know-the-total-size-taken-by-specific-kind-of-files-in-my-hard-drive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?