-2

I need to check the used space in some folders, and I need it to be fast to check because it will be inside a script.

Which command should I use, "du -h" or "df -h"??

4 Answers 4

3

Well, they don't do the same thing, so it's a fairly easy choice! df reports file-system usage. du reports usage for directories.

2

You want du as it gives you the space used by specific files and/or folder(s). df is used for checking the space used on entire filesystems.

1

Clearly the answer is du, as the prior respondents stated. If you want to specify the exact directories you're interested in and only want a summary for each then you would use:

du -hs /path/to/dir1
du -hs /path/to/dir2
etc
0

df reports on file systems, du measures directory contents.

Based on your requirements, use: du -h

4
  • Ok, but du still takes a lot of time to finish. Is there any way to check the space used in less time than du?
    – Shirkkan
    Aug 29, 2011 at 11:14
  • I don't think du can be sped up; it depends on the directory tree you're trying to check. Depending on what your actual requirements are, doing a find for files larger than a specific size may be more appropriate? Aug 29, 2011 at 11:19
  • I can't exclude files because I try to get the used space for a hosting, so it must include everything. So, in large hostings, it takes too long and the method returns an Internal Timeout.
    – Shirkkan
    Aug 29, 2011 at 11:52
  • If speed is really a need, make your directory a mount point for a separate file system.
    – Xenoactive
    Aug 30, 2011 at 3:37

You must log in to answer this question.