3

I ran du -hs to find out how big my /home/user directory was and it reported as 18G. I cleared out almost 4G of data and ran du -hs again to find out how much space I actually saved and it still reports as 18G. --apparent-size makes it report as 19G. What am I doing wrong?

Cristian Ciupitu
  • 6,396
  • 2
  • 42
  • 56
Danny Dyla
  • 153
  • 4

3 Answers3

3

If the files are still in use, du will not update.

Here's a post with an exercise so you can see this in action : (for BSD, but it's equivalent in Linux)

Khaled
  • 36,533
  • 8
  • 72
  • 99
Hyppy
  • 15,608
  • 1
  • 38
  • 59
1

Another possibility that can cause this is filesystem compression and utilities that don't know about it. I saw this with ZFS a few years ago on Solaris but the theory should be the same for Ubuntu and any other filesystem that supports compression.

I created a file with mkfile 10g test. After this, ls -lh reported it as 10GB and du -h reported it as 0.

If the 4GB you cleared out was found with ls -lh then it might not have been taking up nearly as much space as it seemed.

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
  • 1
    Something similar can also happen with *sparse files*. `dd if=/dev/zero of=test bs=10G seek=1 count=0` creates a file that `ls -lh` reports as having 10GBs. – Cristian Ciupitu Jun 18 '12 at 23:07
1

This could be caused by hard links which means that the files you deleted still exist under other names. To find them, run find -type f -links +1.

Cristian Ciupitu
  • 6,396
  • 2
  • 42
  • 56