一个文件的大小怎么可能是零?

我们偶尔都会在电脑上遇到一个让我们完全困惑的“情况”,比如一个大小为零的文件,但这怎么可能呢?今天的超级用户问答有一个困惑读者的问题的答案。...

一个文件的大小怎么可能是零?

我们偶尔都会在电脑上遇到一个让我们完全困惑的“情况”,比如一个大小为零的文件,但这怎么可能呢?今天的超级用户问答有一个困惑读者的问题的答案。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者Eugene S想知道文件大小如何为零:

This is something that I ran into and could not think of a proper explanation. If I create an empty *.txt file on my computer and then look at its size, it shows a size of zero. How is that possible? I mean even if the file itself is empty, it must still have some size (even it if is just to store its own name). How can this be explained?

文件的大小怎么可能为零?

答案

超级用户贡献者David Schwartz和Cort Ammon为我们提供了答案。首先,大卫·施瓦茨:

It is possible because there really is no file. There is just a directory entry with a name and owner. The directory entry is logically distinct from the file. For example, the same file can have more than one name in more than one directory.

Unfortunately, the term file is not always used to mean precisely the same thing. But the file size logic comes from the model where a directory entry attaches a file to a directory, then the file names and related meta data are stored in the directory.

接下来是Cort Ammon的回答:

The semantic meaning of file size is different from the one you are using.

There are many file sizes which are meaningful. The most common one, and the one you are seeing here, is the number of bytes in the file. If the file is an empty text file, it may indeed contain zero bytes. This number is important to programmers because we often need to open a file, read all the data, and close it. We need to know how many bytes of data will be in the file so we can plan ahead.

Another meaning arises from the way most file systems store data. Most file systems store data in blocks. For example, the file system may store data in 64 kB blocks, meaning it will never allocate anything which is not an even multiple of 64 kB. This sounds inefficient, but it can make bookkeeping quite a bit simpler, and often simpler means faster.

A third meaning, which you are tugging at, would be the actual number of bits required on the hard-drive to describe the presence of a file. This includes information that is usually stored separately from the file. For instance, in Linux, the concept of the file name is stored in the inode for the directory containing the file. [Based on input from other comments, this is (technically) stored in the directory’s data. When I wrote this, I was thinking of the **all-directory case. Data **aller than 156 bytes can be stored directly in the inode.] This is not a commonly used meaning because it is terribly hard to determine without knowing the tremendously deep inner workings of your file system (such as accounting for the space needed to store all the permissi*** on the file). However, if you have a 1,000,000 byte hard-drive and want to know how big of a file can fit on that hard-drive, this will be a very important meaning to you!


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-10 05:56
  • 阅读 ( 139 )
  • 分类:互联网

你可能感兴趣的文章

不,linux不需要防病毒或防火墙

...你需要防病毒软件或防火墙软件。尽管您可能会决定安装一个,但这并没有什么错,这里有一些原因说明它可能没有您想象的那么有用。 ...

  • 发布于 2021-03-12 20:15
  • 阅读 ( 187 )

知道何时使用哪种文件格式:png与jpg、doc与pdf、mp3与flac

... 所以,如果你是一个信息生产者,你怎么知道什么文件格式使用?答案归结为您希望如何分发或使用该文件。 ...

  • 发布于 2021-03-14 05:40
  • 阅读 ( 398 )

更改linuxgnome桌面字体比您想象的要简单

...OME调整工具是从根本上改变你在屏幕上看到的一切。但有一个巨大的,看似明显的疏忽。这些工具不允许您更改所有字体。 ...

  • 发布于 2021-03-14 23:39
  • 阅读 ( 206 )

什么是零日攻击?攻击是如何工作的?

当一个软件不断要求用安全补丁来更新自己时,这可能会令人沮丧,但它们对设备的安全非常重要。当程序不断更新时,它能更好地保护自己免受可怕的零日攻击,并保证您的安全。 ...

  • 发布于 2021-03-26 16:55
  • 阅读 ( 269 )

如何减小powerpoint演示文稿的文件大小

...区别呢?PPTX版本压缩演示文稿中的所有内容。如果您有一个PPT文件并将其转换为PPTX文件,您会注意到文件大小的减小。 转换文件非常简单,只需按一个按钮并选择文件类型。继续打开你的PPT文件,进入“文件”选项卡,然后单...

  • 发布于 2021-04-03 11:34
  • 阅读 ( 204 )

如何使用邮箱清理清除outlook文件夹中的垃圾

...你有几年的约会和会议请求,你可以很容易地在日历中有一个相当大的千字节块,你可以通过删除旧事件来清理它。 如果要查看邮件服务器上文件夹的大小,请单击“服务器数据”选项卡。第一次打开此选项卡时,可能需要一...

  • 发布于 2021-04-04 07:38
  • 阅读 ( 207 )

我的usb驱动器应该使用什么文件系统?

...案。 如果您想与大多数设备共享您的文件,并且没有一个文件大于4 GB,请选择FAT32。 如果您有大于4 GB的文件,但仍然希望跨设备提供良好的支持,请选择exFAT。 如果您的文件大于4 GB,并且大部分与Windows PC共享,请选择NTFS。...

  • 发布于 2021-04-07 13:30
  • 阅读 ( 159 )

如何在osxfinder中自定义文件夹视图

...位到了右侧。 请注意,当您在图标视图中时,右下角有一个小滑块,可以让您快速更改图标大小。您还可以通过双击以前的位置快速导航回文件夹的路径。 如果看不到路径(或这些屏幕截图中的任何其他查找器元素),可以...

  • 发布于 2021-04-10 22:22
  • 阅读 ( 181 )

为什么即使我用ffmpeg改变了比特率,mp3文件的大小也一样?

...你怎么解决这个问题呢?今天的超级用户问答帖子回答了一个困惑读者的问题。 今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。 图片由Warein(Flickr)提供。 问题 超级...

  • 发布于 2021-04-11 03:25
  • 阅读 ( 162 )

如何将非常大的文件上载到skydrive、dropbox或电子邮件

你是否需要上传一个非常大的文件到网上存储或者给朋友发邮件?不幸的是,无论您是通过电子邮件发送文件还是使用SkyDrive之类的在线存储站点,您可以使用的文件大小都有限制。下面是如何绕过限制。 Skydrive只允许您添加50M...

  • 发布于 2021-04-13 03:57
  • 阅读 ( 160 )
返猿锰254
返猿锰254

0 篇文章

相关推荐