Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get the size of a directory by ls

Tags:

directory

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?

like image 783
Léo Léopold Hertz 준영 Avatar asked Nov 28 '22 05:11

Léo Léopold Hertz 준영


2 Answers

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).

like image 199
Sean Bright Avatar answered Dec 04 '22 09:12

Sean Bright


If you want to get directories size, you can use

du -sh
like image 35
Jakub Arnold Avatar answered Dec 04 '22 10:12

Jakub Arnold