{{Short description|Computer file containing no data}} {{Multiple issues| {{refimprove|date=July 2021}} {{Notability|date=April 2023}} }} A '''zero-byte file''' or '''zero-length file''' is a computer file containing no data. As the size (a.k.a. length) of a file is often measured in bytes, such a file has length of zero bytes.{{sfnp|Mathai|2019}}
Although there are many ways to create a zero-byte file, one common way to intentionally create one is via the <code>touch</code> command. The command line <code>touch abc</code> creates a zero-byte file named {{mono|abc}}.
The creation of any file involves creating it with zero length, but usually data is written to a new file almost immediately after creation such that users don't generally notice files in a zero-byte state. The presence of a zero-byte file may indicate a failure of a program. One common scenario involves caching data in memory and then flushing to storage at a later time. A program that does not flush to storage (i.e. due to abnormal termination) may erroneously leave a zero-byte file. Sometimes, the time between file creation and writing data to it is long enough that a user does notice that the file has zero size before a program writes any content.
Even a zero-byte file requires storage space since every file has file system metadata. The file system may allocate a minimum size of space to every file. Such file system parameters may be discovered via an operating system utility such as <code>stat</code>.<ref>{{Cite web |last=Team |first=Tech Insight |date=2020-08-07 |title=Size vs Size on Disk - Why is there a difference? |url=https://www.businesstechweekly.com/tech-insights/size-vs-size-on-disk/ |access-date=2023-09-27 |website=Businesstechweekly.com |language=en-GB}}</ref><ref>{{Cite web |title=Understanding IO Block size |url=https://unix.stackexchange.com/questions/345984/understanding-io-block-size |access-date=2023-09-27 |website=Unix & Linux Stack Exchange |language=en}}</ref> Often this size is 4096 bytes.
Some file formats include metadata (separate from file system metadata). In this case, a file that contains no content may have non-zero size. For example, a word processor document with no text, an image with zero-by-zero dimensions, or an audio sample of zero duration may contain metadata which makes the size of the file non-zero. On the other hand, some file formats have no metadata. For example, an ASCII text file has no metadata such that a file with no content has zero size. But, some text file formats do include a byte order mark header that describes the encoding {{endash}} making a file with no content non-zero in size.
== Uses == A zero-byte file is sometimes used for intentional purposes. For example, a user might find a zero-byte file named {{mono|documents-moved-to-partition-D}} in an otherwise empty directory and then know to look in partition D for the files that used to be in that directory. Sometimes, a zero-byte file is added to a directory to ensure that it is not empty since some tools (such as backup and revision control software) ignore an empty directory.
The presence or absence of a file with a particular name can be used to direct program control flow. For example:
<syntaxhighlight lang="batch"> IF EXIST C:\NOTHING.TXT EXIT IF NOT EXIST C:\NOTHING.TXT GOTO START :START REM Create the zero-length file C:\>type null>nothing.txt :EXIT </syntaxhighlight>
== References == {{reflist}}
== Bibliography == * {{cite web |last1=Mathai |first1=Anith |title=Zero-byte files. A big problem in eDiscovery. What are they, and is there anything you can do about them? |date=2019 |url=https://www.linkedin.com/pulse/zero-byte-files-big-problem-ediscovery-what-anything-you-anith-mathai |website=www.linkedin.com |language=en}}
{{Computer files}}
Category:Computer files
{{software-type-stub}}