choose between df and du in linux

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

Shirkkan

Posted 2011-08-29T11:02:32.260

Reputation:

Answers

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.

Oliver Charlesworth

Posted 2011-08-29T11:02:32.260

Reputation: 972

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.

JJ01

Posted 2011-08-29T11:02:32.260

Reputation: 223

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

gview

Posted 2011-08-29T11:02:32.260

Reputation: 506

0

df reports on file systems, du measures directory contents.

Based on your requirements, use: du -h

Stuart McLaughlin

Posted 2011-08-29T11:02:32.260

Reputation: 942

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? – None – 2011-08-29T11:14:37.007

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 – 2011-08-29T11:19:55.123

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. – None – 2011-08-29T11:52:19.273

If speed is really a need, make your directory a mount point for a separate file system. – Xenoactive – 2011-08-30T03:37:17.710