Take the 2-minute tour ×
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

4 Answers 4

up vote 4 down vote accepted

Try doing this :

du -s dir

or

du -sh dir

needs -h support, depends of your OS.

See

man du
share|improve this answer

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

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 http://dev.yorhel.nl/ncdu/scr

share|improve this answer

Your Answer

 
discard

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.