Ubuntu – Du (disk usage) reports 6.1M but directory is empty

disk-usage

This does not make any sense!

user@localhost:~/folder$ du -h --max-depth=1
6.1M    ./subfolder
6.1M    .
user@localhost:~/folder$ ls -la subfolder
total 6228
drwx------ 2 user user 6369280 2013-07-08 16:03 .
drwx------ 9 user user    4096 2013-07-08 16:04 ..

du reports 6.1 megabytes, ls reports a total of "6228" (I don't know total of what)… but the folder is empty… indeed, there is no file there and it should be empty indeed.

Why is that? Can someone explain this to me?

This is happening in a VPS running Ubuntu 10.04

Thank you.

Best Answer

You're looking at a result of how Ext2/3/4 filesystems work. The list of files (inodes) in the directory is kept as the directory 'file', represented as the . in the listing. After removing the files in the directory, the disk usage does not shrink.

Therefore, I assume you had a lot of files in the directory before (or you're omitting them in the ls output in your question). The only solution is to remove and recreate the directory to free up this space.

See also: Why could the size of the “dot file” /. exceed 4096?

For as to what the total 6228 means, see ls command: what does the first line mean?