一個檔案的大小怎麼可能是零?

我們偶爾都會在電腦上遇到一個讓我們完全困惑的“情況”,比如一個大小為零的檔案,但這怎麼可能呢?今天的超級使用者問答有一個困惑讀者的問題的答案。...

一個檔案的大小怎麼可能是零?

我們偶爾都會在電腦上遇到一個讓我們完全困惑的“情況”,比如一個大小為零的檔案,但這怎麼可能呢?今天的超級使用者問答有一個困惑讀者的問題的答案。

今天的問答環節是由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
  • 閱讀 ( 31 )
  • 分類:網際網路

你可能感興趣的文章

谷歌新推出的檔案go應用程式:你需要知道的一切

... 話雖如此,讓我們做一個簡短的概述,所有的事情,你可以做的檔案去。 ...

  • 發佈於 2021-03-12 07:08
  • 閲讀 ( 45 )

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

...你需要防病毒軟體或防火牆軟體。儘管您可能會決定安裝一個,但這並沒有什麼錯,這裡有一些原因說明它可能沒有您想象的那麼有用。 ...

  • 發佈於 2021-03-12 20:15
  • 閲讀 ( 51 )

如何在iphone和ipad上使用ios11的新檔案應用程式

...的蘋果風格下,它不會暴露任何型別的系統功能。它只是一個應用程式,你可以檢視所有儲存在你的裝置(在應用程式中)和各種雲端儲存服務的檔案。 ...

  • 發佈於 2021-03-13 02:03
  • 閲讀 ( 49 )

在linux中檢視磁碟使用情況的7大應用程式

... 您應該嘗試的第一個命令是df。這將報告正在使用的磁碟空間量。它可以單獨使用,顯示所有裝入的檔案系統的完整總數,也可以使用一個檔名。 ...

  • 發佈於 2021-03-13 08:13
  • 閲讀 ( 40 )

6個免費的雜湊檢查程式來檢查任何檔案的完整性

當您線上下載檔案時,系統會向您提供一個檔案雜湊來檢查檔案的完整性。不管是對是錯,大多數人忽略了檔案雜湊驗證,假設檔案是惡意的,網站所有者會意識到並將其刪除。或者他們的防毒軟體會在可疑下載執行之前將其踩...

  • 發佈於 2021-03-19 07:54
  • 閲讀 ( 43 )

windows 10上的儲存空間不足?幫助回收磁碟空間的5個技巧

... 尤其是當你是一個遊戲玩家或設計師,使用的電腦上裝載著大量的檔案,資料夾和程式。你可能在問“我已經把所有的清潔工都跑出去了,接下來呢?”繼續讀! ...

  • 發佈於 2021-03-23 15:14
  • 閲讀 ( 50 )

透過網路與任何人共享檔案的15種最佳方式

... 只需拖放一個檔案,為該檔案生成一個URL,然後讓收件人訪問該連結。您的瀏覽器與其瀏覽器建立了連線,檔案將直接傳送。在完全傳輸期間,兩個瀏覽器必須保持開啟狀態。 ...

  • 發佈於 2021-03-25 02:54
  • 閲讀 ( 63 )

如何在mac上製作zip檔案

如果你想在你的Mac上**一個ZIP檔案,有很多方法可以做到。macOS提供了內建的工具,但也有第三方應用程式可以讓你在Mac上建立ZIP檔案。 ...

  • 發佈於 2021-03-28 16:40
  • 閲讀 ( 66 )

torrent定義:什麼是torrent,如何使用它?

...詞。儘管事實上,你可以合法下載各種各樣的大檔案使用一個種子,連結到非法內容是非常強大的。 ...

  • 發佈於 2021-03-30 18:54
  • 閲讀 ( 55 )

如何在linux上使用join命令

...果您需要整合資料或跨整個資料集進行一些分析,您還有一個問題。在處理不同檔案的資料之前,如何使其合理化?如何進入資料準備階段? 好訊息是,如果這些檔案至少共享一個公共資料元素,那麼linuxjoin命令可以讓您擺脫...

  • 發佈於 2021-04-02 15:30
  • 閲讀 ( 44 )
返猿錳254
返猿錳254

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦