Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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"??

share|improve this question

migrated from Aug 29 '11 at 12:50

This question came from our site for professional and enthusiast programmers.

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.

share|improve this answer

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.

share|improve this answer

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
share|improve this answer

df reports on file systems, du measures directory contents.

Based on your requirements, use: du -h

share|improve this answer
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 '11 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? – Stuart McLaughlin Aug 29 '11 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 '11 at 11:52
If speed is really a need, make your directory a mount point for a separate file system. – Xenoactive Aug 30 '11 at 3:37

You must log in to answer this question.