Computer file


A computer file is a named collection of data treated as a unit by the system that manages it. Today, this system is called a file system. Many older computer systems lacked a distinct file system per se, yet a management feature is required in order to provide a file abstraction.
Files can be shared with and transferred between computers and mobile devices via removable media, networks, or the Internet.
Different types of computer files are designed for different purposes. A file may be designed to store a written message, a document, a spreadsheet, an image, a video, a program, or any wide variety of other kinds of data. Certain files can store multiple data types at once.
By using computer programs, a person can open, read, change, save, and close a computer file. Computer files may be reopened, modified, and copied an arbitrary number of times.

Etymology

The word "file" derives from the Latin filum.
In extended use the English term "file" came to refer to various systems of arranging papers and documents for retrieval.
"File" was used in the context of computer storage as early as January 1940. In Punched Card Methods in Scientific Computation, W. J. Eckert stated, "The first extensive use of the early Hollerith Tabulator in astronomy was made by Comrie. He used it for building a table from successive differences, and for adding large numbers of harmonic terms". "Tables of functions are constructed from their differences with great efficiency, either as printed tables or as a ."
In February 1950, in a Radio Corporation of America advertisement in Popular Science magazine describing a new "memory" vacuum tube it had developed, RCA stated: "the results of countless computations can be kept 'on file' and taken out again. Such a 'file' now exists in a 'memory' tube developed at RCA Laboratories. Electronically it retains figures fed into calculating machines, holds them in storage while it memorizes new ones – speeds intelligent solutions through mazes of mathematics."
In 1952, "file" denoted, among other things, information stored on punched cards.
In early computing usage, the word "file" could refer to the underlying hardware, rather than to the contents stored on it. For example, the IBM 350 disk drives were denominated "disk files". The introduction,, by the Burroughs MCP and the MIT Compatible Time-Sharing System of the concept of a "file system" that managed several virtual "files" on one storage device is the origin of the contemporary denotation of the word. Although the contemporary "register file" demonstrates the early concept of files, its use has greatly decreased.

File system

A file system provides the file abstraction to consuming software—it enables software to organize, name, and manipulate data as files. Although early computers did not contain a distinct file system, the function of what we call file system today is required as was often provided directly by the core operating system.
Not only do modern computer systems include a file system, some systems use multiple. Unix-like systems typically allow for using multiple file systems. On some Windows systems, the older FAT-type file systems of MS-DOS and old versions of Windows are supported, in addition to the NTFS file system that is the normal file system.

File manager

A file manager is a utility that allows a user to manipulate files directly. Typically, it allows one to move, create, delete and rename files and directories, although it may not directly support viewing file content. Typically, a computer system has at least one file manager program for its native file system. For example, File Explorer is commonly used in Windows, and Nautilus is in several Linux distributions.

File contents

On most modern operating systems, files are organized into one-dimensional arrays of bytes. The format of a file is defined by its content since a file is solely a container for data.
On some platforms the format is indicated by its filename extension, specifying the rules for how the bytes must be organized and interpreted meaningfully. For example, the bytes of a plain text file are associated with either ASCII or UTF-8 characters, while the bytes of image, video, and audio files are interpreted otherwise. Most file types also allocate a few bytes for metadata, which allows a file to carry some basic information about itself.
Some file systems can store arbitrary file-specific data outside of the file format, but linked to the file, for example extended attributes or forks. On other file systems this can be done via sidecar files or software-specific databases. All those methods, however, are more susceptible to loss of metadata than container and archive file formats.

File size

File size is a measure of the storage space allocated to the file. Although often expressed in units of bytes, many older file systems tracked size in larger units such as blocks or tracks. None-the-less, sometimes a more precise measure was available. For example, CP/M marked the end of a text file with Ctrl-Z which could be used to obtain a size with byte precision.
Typically, due to its design, a file system limits maximum file size.

Organization of data in a file

Information in a computer file can consist of smaller packets of information that are individually different but share some common traits. For example, a payroll file might contain information concerning all the employees in a company and their payroll details; each record in the payroll file concerns just one employee, and all the records have the common trait of being related to payroll—this is very similar to placing all payroll information into a specific filing cabinet in an office that does not have a computer. A text file may contain lines of text, corresponding to printed lines on a piece of paper. Alternatively, a file may contain an arbitrary binary image or it may contain an executable.
The way information is grouped into a file is entirely up to how it is designed. This has led to a plethora of more or less standardized file structures for all imaginable purposes, from the simplest to the most complex. Most computer files are used by computer programs which create, modify or delete the files for their own use on an as-needed basis. The programmers who create the programs decide what files are needed, how they are to be used and their names.
In some cases, computer programs manipulate files that are made visible to the computer user. For example, in a word-processing program, the user manipulates document files that the user personally names. Although the content of the document file is arranged in a format that the word-processing program understands, the user is able to choose the name and location of the file and provide the bulk of the information that will be stored in the file.
Many applications pack all their data files into a single file called an archive file, using internal markers to discern the different types of information contained within. The benefits of the archive file are to lower the number of files for easier transfer, to reduce storage usage, or just to organize outdated files. The archive file must often be unpacked before next using.

File operations

The most basic operations that programs can perform on a file are:
  • Create a new file
  • Change the access permissions and attributes of a file
  • Open a file, which makes the file contents available to the program
  • Read data from a file
  • Write data to a file
  • Delete a file
  • Close a file, terminating the association between it and the program
  • Truncate a file, shortening it to a specified size within the file system without rewriting any content
  • Allocate space to a file without writing any content. Not supported by some file systems.
Files on a computer can be created, moved, modified, grown, shrunk, and deleted. In most cases, computer programs that are executed on the computer handle these operations, but the user of a computer can also manipulate files if necessary. For instance, Microsoft Word files are normally created and modified by the Microsoft Word program in response to user commands, but the user can also move, rename, or delete these files directly by using a file manager program such as Windows Explorer or by command lines.
In Unix-like systems, user space programs do not operate directly, at a low level, on a file. Only the kernel deals with files, and it handles all user-space interaction with files in a manner that is transparent to the user-space programs. The operating system provides a level of abstraction, which means that interaction with a file from user-space is simply through its filename. For example, rm filename will not delete the file itself, but only a link to the file. There can be many links to a file, but when they are all removed, the kernel considers that file's memory space free to be reallocated. This free space is commonly considered a security risk. Any secure-deletion program uses kernel-space functions to wipe the file's data.
File moves within a file system complete almost immediately because the data content does not need to be rewritten. Only the paths need to be changed.

Moving methods

When moving files between devices or partitions, some file managing software deletes each selected file from the source directory individually after being transferred, while other software deletes all files at once only after every file has been transferred.
For example, the mv command uses the former method when moving files individually with wildcards, but uses the latter method when moving entire directories.
Microsoft Windows Explorer also varies its approach: it uses the former method for mass storage file moves, but uses the latter method when transferring files via Media Transfer Protocol, as described in.
The former method has the benefit that space is released from the source device or partition imminently after the transfer has begun, meaning after the first file is finished. With the latter method, space is only freed after the transfer of the entire selection has finished.
If an incomplete file transfer with the latter method is aborted unexpectedly, perhaps due to an unexpected power-off, system halt or disconnection of a device, no space will have been freed up on the source device or partition. The user would need to merge the remaining files from the source, including the incompletely written last file.
With the individual deletion method, the file moving software also does not need to cumulatively keep track of all files finished transferring for the case that a user manually aborts the file transfer. A file manager using the latter method will have to only delete the files from the source directory that have already finished transferring.