2

I'm trying to get the disk usage of everything within certain directories, which I've been attempting to do with commands like this:

df -h -k /var/www/html/exampledirectory1
df -h -k /var/www/html/exampledirectory2
df -h -k /var/www/html/exampledirectory3

The problem is, that every single directory in the server (even if I just run 'df -h' while within a certain directory) is giving me the exact same numbers, down to the Kilobyte.

Obviously this can't be correct, but I have no idea what it is I'm doing wrong. Can anyone help me out?

(I'm using BASH version 4.2.25 and I'm running Ubuntu 14.10)

Thorium
  • 191
  • 1
  • 14
  • 1
    The `df` command is 'disk free' — how much space is available for use. There's the same amount of space free on a given file system regardless of which directory or file you specify to identify the file system. The `du` command is 'disk usage' — how much disk space is used by a given directory or file. That typically varies quite a lot. – Jonathan Leffler Apr 29 '15 at 05:32
  • `df` is not a `bash` command, it is an independent program. You just happen to be using `bash` to invoke it. Try `type df`. `cd` is a `bash` command, try `type cd`. – cdarke Apr 29 '15 at 06:53

1 Answers1

6

You want to use the du command. df is used for measuring disk usage of a whole partition. Here is an example to determine the disk spaced used by a directory and all sub-directories:

du -sh /home/darwin
Darwin
  • 519
  • 2
  • 11
  • *plus* 1 for the 'h' flag – Throwback1986 Apr 29 '15 at 04:13
  • Thank you :) How accurate is 'du'? Doesn't it only give estimates? – Thorium Apr 29 '15 at 04:33
  • @Thorium It displays the actual disk space used by files since it counts blocks making it more accurate if you are looking at disk usage. The difference between actual file size and the space the file occupies on the filesystem is referred to as [slack space](https://en.wikipedia.org/wiki/File_system#Aspects_of_file_systems). ------ So, if your filesystem allocates space in units of 16 KB, and you store a 1 KB file, then: - the file's actual size is 1 KB. - the file's occupied space size is 16 KB, as the remaining 15 KB in that unit can't be allocated to another file and is lost. – Darwin Apr 29 '15 at 04:59