2
drwxrwxr-x 2 xyz xyz 176128 Jul 29 02:03 20170429  
drwxrwxr-x 2 xyz xyz 110592 Jul 31 01:22 20170430

cd 20170429  
ls -lart  
total 196  
drwxrwxr-x   2 xyz xyz 176128 Jul 29 02:03 .  
drwxrwxr-x 253 xyz xyz 20480 Aug  4 00:00 ..  


du -sh 20170429
176K    20170429

du -sh 20170430
124K    20170430

Referring to the above information, I wanted to know for the empty directories 20170429, 20170429 , why is it still showing having memory space of 176128 and 176128 while we do ls -lrt. Where from do these information comes from? Is it from inode? Also note that even by du -sh they still shows 176k and 124k respectively for the empty directory.

ilkkachu
  • 138,973

1 Answers1

0

My guess is that the directory has contained a large number of files in the past and the filesystem does not truncate the directory entry upon deleting files.

Example:

$ mkdir test_dir

$ du -h test_dir
2.0K    test_dir

$ touch test_dir/file{001..500}-{01..10}

We now have a directory with 5000 empty files in it.

$ du -h test_dir
102K    test_dir

The size comes solely from the directory entries of the empty files.

$ rm test_dir/file*

$ du -h test_dir
102K    test_dir

The size does not decrease (on this filesystem) as the files are deleted.

Kusalananda
  • 333,661
  • Did you do this on a local filesystem or NFS? Your example #1 shouldn't work that way on a local filesystem like ext. du won't find and add up the size of the deleted file. – BowlOfRed Oct 05 '17 at 21:41
  • @BowlOfRed Ah. I'm running on NFS. I will add that little bit of info to the answer. Thanks! – Kusalananda Oct 05 '17 at 21:49
  • @roaima It's apparent that I was wrong with that assumption, cutting answer down a bit. – Kusalananda Oct 05 '17 at 22:33