Short command to find total size of files matching a wild card


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


Try du to estimate file space 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


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 {} +


For don't show files list, and just show total size, use this:

du -ch *.php.* | grep total


196M total


  • VSTS Build Definition for Android failing
  • How to test each date field in the array response using Karate
  • Aligning bullets in JasperReports
  • Error ORA-12638 in Oracle Database 11g
  • Is it possible to generate a Visual Studio Code extension with C#?
  • Why would javascript work on my Sony Ericsson C510 browser, but not javascript + jquery?
  • Android How to capture two consecutive frames from camera
  • How to neatly align text in a textbox and keep it when exporting to .txt
  • Using `git clean` in a folder deleted its contents
  • How to get some user identity information in HTTP when SESSION_COOKIE_SECURE = True
  • Unit testing entire project hierarchy in Python using unittest in pydev
  • Android: How to start an Activity in the background?
  • can an android application check the version of the phone
  • Pass type to generic function and compare
  • R web scraper with jsessionid
  • MySQL error “empty string given as argument for ! character”
  • Is there any simple Java FTP Server libraries that is embeddable?
  • Stream scheduling order
  • Turning an array of jquery objects into html
  • Convert certificate to byte array
  • No suggestions when code snippets are used in sublime
  • getting the values of checkboxes in a checkboxlist control
  • Validating a Firebase Key [duplicate]
  • Convert current tmux session to configuration file
  • cSPADE data mining in R using arulesSequences - Error while converting to “transactions” format
  • select an input by value?
  • openpyxl - adding new rows in excel file with merged cell existing
  • Create an average of multiple excel chart without the data source
  • How to configure the APNS.Certificate in the arm template
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • Bad automatic Triangulation with Mayavi for coloring a surface known only by its corner