2

I 'm running the du command on one of my websites directories and I'm getting 2 different result, I'm confused which one is accurate and why there is a big difference, here both command and the output.

du -hsc directory_name/
5.3G    directory_name/
5.3G    total


du -hsc directory_name/*
4.0K    directory_name/announcements.php
4.0K    directory_name/articles.php
1.2M    directory_name/election2011
4.3M    directory_name/error_log
78M directory_name/files
3.0G    directory_name/php
3.1G    total

Thanks

2 Answers 2

0

Could you post the command and outputs in a easy to read format using next lines?

I suspect that the size is not different at all ...

When you type "du -hsc dir_name", you are asking for the size of "dir_name".

But when you type "du -hsc dir_name/*", you are asking for the size of all directories and files inside of "dir_name". So the sum of all the files yielded by "du -hsc dir_name/*" should amount to the sum of "du -hsc dir_name".

Hope that helps.

EDIT

I found the following (http://www.linfo.org/du.html):

"A somewhat similar report is provided by using the star ( * ) wildcard, which will match any character or characters. For example, the following command would list the sizes of all directories that are in the tree that begins with the current directory:

du *

However, the only files listed are those in the the parent directory, not those in its subdirectories. Also, no total for the directory tree as a whole is provided.

The use of the -s option and the star wildcard together would cause du to report the names and sizes of only the files and directories contained directly in the top level directory itself (and to not list the names of any of its subdirectories and the files in them). The size of each listed directory is, of course, inclusive of all of its files and subdirectories (including all of the files in them). For example, such a report about the directory tree beginning with the current directory would be provided by the following:

du -hs *

The wildcard can also be used to filter the output to list only those items whose names begin with, contain or end with certain characters or sequences of characters. For example, the following would report the names and sizes of all of the directories and files in the current directory whose names begin with the letter s as well as the names and sizes of all levels of subdirectories of those directories regardless of what their names begin with:

du -h s*"

Note where I bolded. Looks like the wildcard only gets the directories in the parent directory and no sum is provided.

2
  • Thanks, I have formatted the output, so it's easier to read now. I'm not quite understand your answer. if I'm using"du -hsc dir_name" I should get the total size of it including it's sub files and directories is this what should I expect or I missing something? Jul 29, 2015 at 14:44
  • I made an edit.
    – Josh Jobin
    Jul 29, 2015 at 16:49
0

If directory_name has hidden files, they will be counted in the first command, but not in the second. The pattern directory_name/* does not include any files that begin with a . (this includes the disk for the directory directory_name).

1
  • No, I don't see any hidden files or directories in that directory. Thanks! Jul 29, 2015 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .