How to know the size of multiple folders on Linux/Unix

Folder IconOften while I’m administrating a Linux/Unix box I come across the tediousus task of freeing up space on the server, usually this task is easily accomplished by issuing a simple “ls -lh” command, you get a nice listing of the files in the current directly along with some nifty details like last modification date and size (the -h parameter for ls allows us to get the size in a human-readable way).

The downsize of doing it this way is that you don’t get to know for real the size of the folders within the current directy, you get a nice total on top of the “ls” listing. A nice command to get the size of a certain folder is issuing a ds

du -sh folder/

This way you’ll get the following result:

pepper:~ pepper$ du -sh perrohunter.com/
694M    perrohunter.com/

You can see that the folder perrohunter.com weights a total of 694 MB. (yeah, that much).

But what if you’d like to know the size of all the folders within the current folder? Piece of cake, just use the * wildcard and that’d do the trick:

du -sh *

And you should get a result similar to the following:

pepper:~ pepper$ du -sh *
628K    application
8.0K    cache
40K    codeigniter
3.6M    database
156K    fonts
180K    helpers
4.0K    index.html
68K    language
536K    libraries
8.0K    logs
36K    plugins
76K    scaffolding

You can see the folders now have the total size of them in MB. Hope this is helpful for you.

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

4 thoughts on “How to know the size of multiple folders on Linux/Unix

  1. perrohunter.com has potential, you can make your
    blog go viral easily using one tricky method. Just search in google:
    Kimting’s Method To Go Viral

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. Hello admin, i must say you have very interesting content
    here. Your blog should go viral. You need initial traffic boost only.
    How to get it? Search for; Mertiso’s tips go viral

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  3. du – sh ./* gives the size of all directories but sorts it by name..
    How can I sort the directory size output by created/mod date of the directory

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *