I want to see how much total space
/ is taking, but I don't know how to do that. I can use
ls -hal and add up the subtotals, or I can use
fdisk to tell me the size of that partition, but is there a better way?
Are you asking about the total size of files/directories contained within
/, or the total size of the root filesystem?
If the former, use
df -h /.
If the latter, you can do this with
du -sh /, which will be very slow, as it has to enumerate every single file. Better, but possibly inaccurate due to things like bind mounts, filesystems stored as sparse files on other filesystems/etc: total up your
There are usually no files in the root directory, so I assume you want to know how much space is used in the root filesystem. The command for this is
df (disk free).
df -h /
With no arguments,
df provides usage information for all filesystems (except some special, non-disk-backed filesystems for which this is irrelevant).
If you want to know how much space is used by a directory and its subdirectories, that don't make up the full filesystem, use
du (disk usage).
dfreports filesystem metadata - i.e. what the filesystem is capable of storing at the moment. Important thing to note is that on some filesystems this does not necessarily need to reflect the free space (it is the available space though), since the fs can do preallocations when it thinks it's a good idea (for example XFS may do this when you start creating a big file - it will allocate additional space to ensure the file is less scattered and doesn't spend too much time with allocations when it will need to write the actual data to disk). Such space is marked as available with some delay. The information also reflects the fact, that some space on the disk is (or might be) needed by the filesystem structures - this can cause a curious effect on some filesystems: reporting more than 100% space use.
duwill give you the real disk usage with filesystem blocks granularity (on most systems, not sure about those that can use one block for data of several files). Since it has to
stat()every file belonging to the top directory hierarchy (the one
duis given on the command line), it's slow, especially for cases with small files.
statwill give you information about a single file (or directory for that matter).
Hence if you want to know:
how much free space you have on a filesystem (approximately), use
how much data you really have in the files (not necessarily on a single filesystem), use
du- be aware that it can easily get slow especially on some network filesystems;
how much space the record for the root directory itself occupies, use