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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to know the size of a directory? Including subdirectories and files.

share|improve this question
up vote 99 down vote accepted
du -s directory_name

Or to get human readable output:

du -sh directory_name

The -s option means that it won't list the size for each subdirectory, only the total size.

share|improve this answer
3  
Actually du's default unit is 512-byte blocks according to POSIX, and kilobytes on Linux (unless the environment variable POSIXLY_CORRECT is set) or with du -k. – Gilles Oct 12 '10 at 17:49
3  
@Gilles: Good catch. I've removed the "number of bytes" bit from my answer. – sepp2k Oct 12 '10 at 17:53
1  
worked as prescribed – skidadon May 28 '15 at 19:17
    
if the directory is very big and have lots of subdirectories, it takes lots of time... almost 1 min.. is that normal? is there a way to get the size more rapidly? – yeahman Oct 15 '15 at 19:59
    
I needed to calculate the size of my folder "bag", du -sh bag worked perfectly! – Toni Almeida Mar 4 at 12:15

you can also use ls -ldh:

ls -ldh /etc drwxr-xr-x 145 root root 12K 2012-06-02 11:44 /etc

-l is for long listing ; -d is for displaying dir info, not the content of the dir, -h is for displaying size in huma readable format.

share|improve this answer
3  
This isn't correct, the person asking is clearly looking for footprint of a directory and it's contents on disk. @sepp2k's answer is correct. – blong Jun 5 '12 at 13:16
    
The ls -ldh command only shows the size of inode structure of a directory. The metric is a reflection of size of the index table of file names, but not the actual size of the file content within the directory. – user2956795 Mar 28 at 18:19

GNU du takes a -b option.

See the man page and the info page for more help:

-b, --bytes is equivalent to --apparent-size --block-size=1

share|improve this answer

I always install the "ncdu" package and see all the output of all directories with graphical representation. This is because I usually need to know what's taking up the most disk space on my machines, regardless of how much a single directory sums up.

Usage: sudo ncdu / (you can use it without sudo for for folder which you have read permissions for).

It will take a while to scan disk usage statistics on the whole file system. It has a nice command line graphical representation and included keyboard navigation using the arrow keys, like going deeper or higher in the scanned path. Also can delete selected items by pressing.

share|improve this answer

While using a separate package such as ncdu may work well, the same comparison of many folders can be done, to some degree, by just giving du a list of folders to size up. For example to compare top-level directories on your system...

cd /    
sudo du -sh ./*
share|improve this answer
    
More simply, du -sh /* – roaima Sep 10 '15 at 17:00

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.