38

I unzipped a zipped file using zip -l <filename> but what get is a dir much smaller than what it was before unzipping. Unzipped dir has all the files mostly videos. Why is the unzipped directory exactly 4.0k? Am I missing something?

Bash output of command ls -alh:

drwxrwsr-x  4 shubhankar gen011    4.0K May 19 15:47 Moments_in_Time_256x256_30fps
-rw-rw-r--  1 shubhankar gen011     73G Mar  1  2018 Moments_in_Time_256x256_30fps.zip
4
  • 6
    Instead of ls -lah, try using du -h on the directory
    – hojusaram
    May 20, 2019 at 2:50
  • 15
    Maybe it would be a good idea to change the question title to something like "Why is my unzipped file only 4KB?" May 20, 2019 at 5:53
  • 4
    @therefromhere No, that would be completely changing the question, and it would be asking about a situation that is not occurring. May 22, 2019 at 1:04
  • 1
    This question is sooooooo duplicated. I wonder why is so highly voted May 22, 2019 at 23:26

1 Answer 1

153

The size of a directory as shown in your screenshot isn't the sum of the size of the contents, it is the size of the meta-data associated with the directory - file names, etc.

https://unix.stackexchange.com/questions/55/what-does-size-of-a-directory-mean-in-output-of-ls-l-command

To find out how much space the directory contents are using, you can use

du -sh /path/to/directory

20
  • 21
    And the answer to just why this design decision was made is left to the reader (after running both commands ;-) ). May 20, 2019 at 11:44
  • 1
    To be fair the filesystem could cache the total size of each directory in the metadata
    – poizan42
    May 20, 2019 at 14:01
  • 11
    @poizan42, no, because files could be hardlinked, so you cannot just sum up sizes when walking up the hierarchy. May 20, 2019 at 14:11
  • 25
    @poizan42 that would be quite inefficient, requiring the filesystem to update all the parents directories at every change (including root dir, its size would change constantly).
    – Erwan
    May 20, 2019 at 15:37
  • 8
    @poizan42 That solution is even worse than it would appear on first glance (which is already unacceptably slow): Inodes do not store references to the directories that link them, but just a count. Meaning you'd also have to store a whole lot more of metadata with each inode and worry about keeping everything in sync. Quite an awful lot of overhead and complexity for what would be a rarely used feature.
    – Voo
    May 21, 2019 at 11:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.