Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Aug 29 '11 at 12:50

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

4 Answers 4

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
etc
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.