文件大小不为零,打开为空_文件大小如何为零?

文件大小不为零,打开为空

文件大小不为零,打开为空

how-can-a-files-size-be-zero-00

We all occasionally run across a ‘situation’ on our computers that leaves us completely baffled, such as a file that has a size of zero, but how is that even possible? Today’s SuperUser Q&A post has the answers to a confused reader’s question.

有时我们所有人都在计算机上遇到一个“情况”,这使我们完全困惑,例如一个大小为零的文件,那怎么可能呢? 今天的“超级用户问答”帖子解答了一个困惑的读者的问题。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

问题 (The Question)

SuperUser reader Eugene S wants to know how a file’s size can be zero:

超级用户阅读器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?

这是我遇到的,无法想到适当的解释。 如果我在计算机上创建一个空的* .txt文件 ,然后查看其大小,则显示大小为零。 那怎么可能? 我的意思是,即使文件本身为空,它也必须具有一定的大小(即使只是为了存储自己的名称也是如此)。 如何解释呢?

How is it possible for a file to have a size of zero?

文件大小怎么可能为零?

答案 (The Answer)

SuperUser contributors David Schwartz and Cort Ammon have the answer for us. First up, David Schwartz:

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

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.

不幸的是,“文件”一词并不总是用来表示同一件事。 但是文件大小逻辑来自模型,其中目录条目将文件附加到目录,然后文件名和相关的元数据存储在目录中。

Followed by the answer from Cort Ammon:

随后是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.

大多数文件系统存储数据的方式也产生了另一种含义。 大多数文件系统将数据存储在块中。 例如,文件系统可能以64 kB块存储数据,这意味着它将永远不会分配不是64 kB偶数倍的任何内容。 这听起来效率低下,但可以使簿记更加简单,并且通常更简单意味着更快。

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 small-directory case. Data smaller 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 permissions 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!

您要提到的第三个含义是硬盘驱动器上描述文件存在所需的实际位数。 这包括通常与文件分开存储的信息。 例如,在Linux中,文件名的概念存储在包含文件的目录的inode中。 [ 根据其他注释的输入,(技术上)将其存储在目录的数据中。 当我写这篇文章时,我想到的是小目录的情况。 小于156字节的数据可以直接存储在inode中。 ]这不是常用的含义,因为在不知道文件系统的内部深度非常深的情况下(例如,考虑存储文件上所有权限所需的空间),很难确定它。 但是,如果您有一个1,000,000字节的硬盘驱动器,并且想知道该硬盘驱动器上可以容纳多少文件,这对您来说将是非常重要的意义!



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/229281/how-can-a-files-size-be-zero/

文件大小不为零,打开为空

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值