I want to read the size of a folder from the command line. ls -lh shows all folders as being 4k, which presumably is the size of the footprint of the folder itself, rather than the contained files. I would like to read the size of all contained files within the folder. is this possible?


You can use the du command:

du -sh foldername
| improve this answer | |
du -s folder

-s stands for summarize.

| improve this answer | |

You can also use

du -csh foldername/*

which gives file and folder sizes under "foldername" separately and the total size in last row.

| improve this answer | |
  • The -c is helpful if you are selecting a subset of files in a folder. For example, if you're trying to see how big your web assets are, you could use du -csh folder/*.js to measure only the JS files, omitting CSS and HTML. – user9320 Apr 9 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.