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
  • 5
    Instead of ls -lah, try using du -h on the directory – hojusaram May 20 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?" – therefromhere May 20 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. – Scott May 22 at 1:04
  • 1
    This question is sooooooo duplicated. I wonder why is so highly voted – Pedro Lobito May 22 at 23:26
151

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

  • 21
    And the answer to just why this design decision was made is left to the reader (after running both commands ;-) ). – Peter A. Schneider May 20 at 11:44
  • 1
    To be fair the filesystem could cache the total size of each directory in the metadata – poizan42 May 20 at 14:01
  • 11
    @poizan42, no, because files could be hardlinked, so you cannot just sum up sizes when walking up the hierarchy. – Simon Richter May 20 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 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 at 11:53

protected by Community May 24 at 17:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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