Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ls to list directories and their total sizes

Tags:

linux

unix

Is it possible to use ls in Unix to list the total size of a sub-directory and all its contents as opposed to the usual 4K that (I assume) is just the directory file itself?

total 12K drwxrwxr-x  6 *** *** 4.0K 2009-06-19 10:10 branches drwxrwxr-x 13 *** *** 4.0K 2009-06-19 10:52 tags drwxrwxr-x 16 *** *** 4.0K 2009-06-19 10:02 trunk 

After scouring the man pages I'm coming up empty.

like image 645
kmorris511 Avatar asked Jun 19 '09 17:06

kmorris511


People also ask

Does ls show directory size?

Using the ls Command–l – displays a list of files and directories in long format and shows the sizes in bytes. –h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes. –s – displays a list of the files and directories and shows the sizes in blocks.

How do I get a list of folder sizes?

Open a file explorer window and right-click on the 'Name' field at the top. You'll see some options – specifically, options, that let you pick what sort of info you want to see about your folders. Select Size and the property will appear on the far right of your window.

How do I check the size of a directory in Linux?

To get the total size of a directory in Linux, you can use the du (disk-usage) command.


1 Answers

Try something like:

du -sh * 

short version of:

du --summarize --human-readable * 

Explanation:

du: Disk Usage

-s: Display a summary for each specified file. (Equivalent to -d 0)

-h: "Human-readable" output. Use unit suffixes: Byte, Kibibyte (KiB), Mebibyte (MiB), Gibibyte (GiB), Tebibyte (TiB) and Pebibyte (PiB). (BASE2)

like image 118
molf Avatar answered Oct 20 '22 09:10

molf