Search code examples
directoryls

Unable to get the size of a directory by ls


I run the command unsuccessfully to get the size of directories (files inside belong to the size of a directory)

ls -lSrh

I get only kilobits for the size of directories while their content is more than that.

How can you list the size of directories including their content in the number by ls?


Solution

  • du -sh directory_name
    

    ls is going to give you the size of the directory entry, not of the directory contents. Based on my quick skim of man ls there doesn't appear to be a way to make ls dive down and calculate the size of the directories (most likely because it would be an expensive operation).