Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I know you are able to see the byte size of a file when you do a long listing with ll or ls -l. But I want to know how much storage is in a directory including the files within that directory and the subdirectories within there, etc. I don't want the number of files, but instead the amount of storage those files take up.

So I want to know how much storage is in a certain directory recursively? I'm guessing, if there is a command, that it would be in bytes.

share|improve this question
See man du, it does exactly this. PS. Don't refer to storage as "memory", it's not. ;) – goldilocks Mar 13 '13 at 16:18
@goldilocks Thanks! – Rob Avery IV Mar 13 '13 at 16:19

5 Answers 5

up vote 21 down vote accepted

Try doing this :

du -s dir


du -sh dir

needs -h support, depends of your OS.


man du
share|improve this answer

You just do:

du -sh /path/to/directory

where -s is for summary and -h for human readable (non standard option).

Be careful however, unlike ls, this will not show you file size but disk usage (i.e. a multiple of the filesystem block-size), but the file may be smaller, or even bigger, so you can use the --apparent-size option:

du -sh --apparent-size /path/to/directory

This is the size that would be transferred over the network if you had to.

Indeed, the file may have "holes" in it (empty shell), may be smaller than the filesystem block-size, may be compressed at the filesystem level, etc. The man page explains this.

You can see this question as well.

share|improve this answer

An alternative to the already mentioned du command would be ncdu which is a nice disk usage analyzer for use in terminal. You may need to install it first, but it is available in most of the package repositories.

Edit: For the output format see these screenshots

share|improve this answer
Miracle! With this I can see which folders that is holding high volume of disk size storage. I even also found all of my files that were mysteriously disappeared. Great tool it is. – Faron Sep 16 at 1:53

In Unix, a directory just contains names and references to filesystem objects (inodes, which can refer to directories, files, or some other exotic things). A file can appear under several names in the same directory, or be listed in several directories. So "space used by the directory and the files inside" really makes no sense, as the files aren't "inside".

That said, the command du(1) lists the space used by a directory and all what is reachable through it, du -s gives a summary, with -h some implementations like GNU du give "human readable" output (i.e., kilobyte, megabyte).

share|improve this answer

Note that if you want to know all {sub}folders size inside a directory, you can also use the -dor --max-depth option of du (which take an argument: the recursive limit)

For instance :

du -h /path/to/directory -d 1

Will show you something like

4.0K /path/to/directory/folder1
16M  /path/to/directory/folder2
2.4G /path/to/directory/folder3
68M  /path/to/directory/folder4
8G   /path/to/directory/folder5

PS: Entering 0 as the recursive limit is equivalent to the -s option. Those 2 commands will give you the same result (your given directory recursive human readable size):

du -h /path/to/directory -d 0
du -sh /path/to/directory
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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