Filename


A filename or file name is a name used to uniquely identify a computer file stored in a file system. Different file systems impose different restrictions on filename lengths and the allowed characters within filenames.
A filename may include one or more of these components:
The components required to identify a file varies across operating systems, as does the syntax and format for a valid filename.
Discussions of filenames are complicated by a lack of standardization of the term. Sometimes "filename" is used to mean the entire name, such as the Windows name c:\directory\myfile.txt. Sometimes, it will be used to refer to the components, so the filename in this case would be myfile.txt. Sometimes, it is a reference that excludes an extension, so the filename would be just myfile.

History

Around this same time appeared the dot as a filename extension separator, and the limit to three letter extensions might have come from 16-bit RAD50 character encoding limits.
Traditionally, most operating system supported filenames with only uppercase alphanumeric characters, but as time progressed, the number of characters allowed increased. This led to compatibility problems when moving files between different file systems.
In 1985, RFC 959 officially defined a pathname to be the character string that must be entered into a file system by a user in order to identify a file.
Around 1995, VFAT, an extension to the MS-DOS FAT filesystem, was introduced in Windows 95 and Windows NT. It allowed mixed-case Unicode long filenames, in addition to classic "8.3" names.

Unicode migration

One issue was migration to Unicode.
For this purpose, several software companies provided software for migrating filenames to the new Unicode encoding.
Mac OS X 10.3 marked Apple's adoption of Unicode 3.2 character decomposition, superseding the Unicode 2.1 decomposition used previously. This change caused problems for developers writing software for Mac OS X.

Number of names per file

Unix-like file systems allow a file to have more than one name; in traditional Unix-style file systems, the names are hard links to the file's inode or equivalent. Windows supports hard links on NTFS file systems, and provides the command fsutil in Windows XP, and mklink in later versions, for creating them. Hard links are different from Windows shortcuts, classic Mac OS/macOS aliases, or symbolic links. The introduction of LFNs with VFAT allowed filename aliases. For example, longfi~1.??? with a maximum of eight plus three characters was a filename alias of "long file name.???" as a way to conform to 8.3 limitations for older programs.
This property was used by the move command algorithm that first creates a second filename and then only removes the first filename.
Other filesystems, by design, provide only one filename per file, which guarantees that alteration of one filename's file does not alter the other filename's file.

Length restrictions

Some filesystems restrict the length of filenames. In some cases, these lengths apply to the entire file name, as in 44 characters on IBM S/370. In other cases, the length limits may apply to particular portions of the filename, such as the name of a file in a directory, or a directory name. For example, 9, 11, 14, 21, 31, 30, 15, 44, or 255 characters or bytes. Length limits often result from assigning fixed space in a filesystem to storing components of names, so increasing limits often requires an incompatible change, as well as reserving more space.
A particular issue with filesystems that store information in nested directories is that it may be possible to create a file with a complete pathname that exceeds implementation limits, since length checking may apply only to individual parts of the name rather than the entire name. Many Windows applications are limited to a MAX_PATH value of 260, but Windows file names can easily exceed this limit .

Filename extensions

Many file systems, including FAT, NTFS, and VMS systems, allow a filename extension that consists of one or more characters following the last period in the filename, dividing the filename into two parts: a base name or stem and an extension or suffix used by some applications to indicate the file type. Multiple output files created by an application use the same basename and various extensions. For example, a compiler might use the extension FOR for source input file, OBJ for the object output and LST for the listing. Although there are some common extensions, they are arbitrary and a different application might use REL and RPT. On filesystems that do not segregate the extension, files will often have a longer extension such as html.

Encoding interoperability

There is no general encoding standard for filenames.
Because file names have to be exchanged between software environments, it is very important not to lose file name information between applications. This led to wide adoption of Unicode as a standard for encoding file names, although legacy software might be non-Unicode-aware.

Encoding indication interoperability

Traditionally, filenames allowed any character in their filenames as long as they were file system safe. Although this permitted the use of any encoding, and thus allowed the representation of any local text on any local system, it caused many interoperability issues.
A filename could be stored using different byte strings in distinct systems within a single country, such as if one used Japanese Shift JIS encoding and another Japanese EUC encoding. Conversion was not possible as most systems did not expose a description of the encoding used for a filename as part of the extended file information. This forced costly filename encoding guessing with each file access.
A solution was to adopt Unicode as the encoding for filenames.
In the classic Mac OS, however, encoding of the filename was stored with the filename attributes.

Unicode interoperability

The Unicode standard solves the encoding determination issue.
Nonetheless, some limited interoperability issues remain, such as normalization, or the Unicode version in use. For instance, UDF is limited to Unicode 2.0; macOS's HFS+ file system applies NFD Unicode normalization and is optionally case-sensitive Filename maximum length is not standard and might depend on the code unit size. Although it is a serious issue, in most cases this is a limited one.
On Linux, this means the filename is not enough to open a file: additionally, the exact byte representation of the filename on the storage device is needed. This can be solved at the application level, with some tricky normalization calls.
The issue of Unicode equivalence is known as "normalized-name collision". A solution is the Non-normalizing Unicode Composition Awareness used in the Subversion and Apache technical communities. This solution does not normalize paths in the repository. Paths are only normalized for the purpose of comparisons. Nonetheless, some communities have patented this strategy, forbidding its use by other communities.

Perspectives

To limit interoperability issues, some ideas described by Sun are to:
Those considerations create a limitation not allowing a switch to a future encoding different from UTF-8.

Uniqueness

Within a single directory, filenames must be unique. Since the filename syntax also applies for directories, it is not possible to create a file and directory entries with the same name in a single directory. Multiple files in different directories may have the same name.
Uniqueness approach may differ both on the case sensitivity and on the Unicode normalization form such as NFC, NFD.
This means two separate files might be created with the same text filename and a different byte implementation of the filename, such as L"\x00C0.txt" and L"\x0041\x0300.txt" .

Letter case preservation

Some filesystems, such as FAT, store filenames as upper-case regardless of the letter case used to create them. For example, a file created with the name "MyName.Txt" or "myname.txt" would be stored with the filename "MYNAME.TXT". Any variation of upper and lower case can be used to refer to the same file. These kinds of file systems are called case-insensitive and are not case-preserving. Some filesystems prohibit the use of lower case letters in filenames altogether.
Some file systems store filenames in the form that they were originally created; these are referred to as case-retentive or case-preserving. Such a file system can be case-sensitive or case-insensitive. If case-sensitive, then "MyName.Txt" and "myname.txt" may refer to two different files in the same directory, and each file must be referenced by the exact capitalization by which it is named. On a case-insensitive, case-preserving file system, on the other hand, only one of "MyName.Txt", "myname.txt" and "Myname.TXT" can be the name of a file in a given directory at a given time, and a file with one of these names can be referenced by any capitalization of the name.
From its original inception, Unix and its derivative systems were case-preserving. However, not all Unix-like file systems are case-sensitive; by default, HFS+ in macOS is case-insensitive, and SMB servers usually provide case-insensitive behavior, and SMB client file systems provide case-insensitive behavior. File system case sensitivity is a considerable challenge for software such as Samba and Wine, which must interoperate efficiently with both systems that treat uppercase and lowercase files as different and with systems that treat them the same.

Reserved characters and words

File systems have not always provided the same character set for composing a filename. Before Unicode became a de facto standard, file systems mostly used a locale-dependent character set. By contrast, some new systems permit a filename to be composed of almost any character of the Unicode repertoire, and even some non-Unicode byte sequences. Limitations may be imposed by the file system, operating system, application, or requirements for interoperability with other systems.
Many file system utilities prohibit control characters from appearing in filenames. In Unix-like file systems, the null character and the path separator / are prohibited.

In Windows

File system utilities and naming conventions on Windows prohibit particular characters from appearing in filenames:
CharacterNameReason for prohibition
/slashUsed as a path name component separator in Unix-like, Windows, and Amiga systems.
\backslashUsed as the default path name component separator in DOS, OS/2 and Windows
?question markUsed as a wildcard in Unix, Windows and AmigaOS; marks a single character. Allowed in Unix filenames, see Note 1.
The symbol "¿" is allowed in all filenames.
%percentUsed as a wildcard in RT-11; marks a single character. Not special on Windows.
*asterisk
or star
Used as a wildcard in Unix, DOS, RT-11, VMS and Windows. Marks any sequence of characters or any sequence of characters in either the basename or extension may be allowed. In Unix, a leading period means the file or folder is normally hidden.
,commaAllowed, but treated as separator by the command line interpreters COMMAND.COM and CMD.EXE on DOS and Windows.
;semicolonAllowed, but treated as separator by the command line interpreters COMMAND.COM and CMD.EXE on DOS and Windows.
=equals signAllowed, but treated as separator by the command line interpreters COMMAND.COM and CMD.EXE on DOS and Windows.
space
Allowed, but the space is also used as a parameter separator in command line applications. This can be solved by quoting the entire filename.

Note 1: While they are allowed in Unix file and folder names, most Unix shells require specific characters such as spaces, <, >, |, \, and sometimes :,, &, ;, #, as well as wildcards such as ? and *, to be quoted or escaped:
five\ and\ six\
'five and six or "five and six

The character 0xE5 was not allowed as the first letter in a filename under 86-DOS and MS-DOS/PC DOS 1.x-2.x, but can be used in later versions.
In Windows utilities, the space and the period are not allowed as the final character of a filename. The period is allowed as the first character, but some Windows applications, such as Windows Explorer, forbid creating or renaming such files. Workarounds include appending a dot when renaming the file, using alternative file managers, creating the file using the command line, or saving a file with the desired filename from within an application.
Some file systems on a given operating system, and particular applications on that operating system, may apply further restrictions and interpretations. See comparison of file systems for more details on restrictions.
In Unix-like systems, DOS, and Windows, the filenames "." and ".." have special meanings. Windows 95/98/ME also uses names like "...", "...." and so on to denote grandparent or great-grandparent directories. All Windows versions forbid creation of filenames that consist of only dots, although names consist of three dots or more are legal in Unix.
In addition, in Windows and DOS utilities, some words are also reserved and cannot be used as filenames. For example, DOS device files:
CON, PRN, AUX, CLOCK$, NUL
COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
LST
KEYBD$, SCREEN$
$IDLE$
CONFIG$
Systems that have these restrictions cause incompatibilities with some other filesystems. For example, Windows will fail to handle, or raise error reports for, these legal UNIX filenames: aux.c, q"uote"s.txt, or NUL.txt.
NTFS filenames that are used internally include:
$Mft, $MftMirr, $LogFile, $Volume, $AttrDef, $Bitmap, $Boot, $BadClus, $Secure,
$Upcase, $Extend, $Quota, $ObjId and $Reparse

Comparison of filename limitations

SystemCase
sensitive
Case
preserving
Allowed character setReserved charactersReserved wordsMaximum length Comments
8-bit FAT??7-bit ASCII first character not allowed to be 0x00 or 0xFF9Maximum 9 character base name limit for sequential files, or maximum 6 and 3 character extension for binary files; see 6.3 filename
FAT12, FAT16, FAT32NoNoany SBCS/DBCS OEM codepage0x00-0x1F 0x7F " * / : < > ? \ | +,. ; = Device names including: $IDLE$ AUX COM1…COM4 CON CONFIG$ CLOCK$ KEYBD$ LPT1…LPT4 LST NUL PRN SCREEN$ 11Maximum 8 character base name limit and 3 character extension; see 8.3 filename
VFATNoYesUnicode, using UCS-2 encoding0x00-0x1F 0x7F " * / : < > ? \ |255
exFATNoYesUnicode, using UTF-16 encoding0x00-0x1F 0x7F " * / : < > ? \ |255
NTFSOptionalYesUnicode, using UTF-16 encoding0x00-0x1F 0x7F " * / : < > ? \ |Only in root directory: $AttrDef $BadClus $Bitmap $Boot $LogFile $MFT $MFTMirr pagefile.sys $Secure $UpCase $Volume $Extend $Extend\$ObjId $Extend\$Quota $Extend\$Reparse 255Paths can be up to 32,000 characters.
Forbids the use of characters in range 1-31 and characters " * / : < > ? \ | unless the name is flagged as being in the Posix namespace. NTFS allows each path component to be 255 characters long.
Windows forbids the use of the MS-DOS device names AUX, CLOCK$, COM1, …, COM9, CON, LPT1, …, LPT9, NUL and PRN, as well as these names with any extension, except when using Long UNC paths. The Win32 API strips trailing period, and leading and trailing space characters from filenames, except when UNC paths are used. These restrictions only apply to Windows; in Linux distributions that support NTFS, filenames are written using NTFS's Posix namespace, which allows any Unicode character except / and NUL.
OS/2 HPFSNoYesany 8-bit set|\?*<":>/254
Mac OS HFSNoYesany 8-bit set:255old versions of Finder are limited to 31 characters
Mac OS HFS+OptionalYesUnicode, using UTF-16 encoding: on disk, in classic Mac OS, and at the Carbon layer in macOS; / at the Unix layer in macOS255Mac OS 8.1 - macOS
most UNIX file systemsYesYesany 8-bit set/ [|null]255a leading . indicates that ls and file managers will not show the file by default
z/OS classic MVS filesystem NoNoEBCDIC code pagesother than $ # @ - x'C0'44first character must be alphabetic or national
"Qualified" contains . after every 8 characters or fewer. Partitioned data sets are divided into members with names of up to 8 characters; the member name is placed in parenthesises after the name of the PDS, e.g. PAYROLL.DEV.CBL
CMS file systemNoNoEBCDIC code pages8 + 8Single-level directory structure with disk letters. Maximum of 8 character file name with maximum 8 character file type, separated by whitespace. For example, a TEXT file called MEMO on disk A would be accessed as "MEMO TEXT A".
early UNIX YesYesany 8-bit set/14a leading . indicates a "hidden" file
POSIX "Fully portable filenames"YesYesA–Z a–z 0–9. _ -/ null14hyphen must not be first character
ISO 9660No?A–Z 0–9 _."close to 180" or 200Used on CDs; 8 directory levels max
Amiga OFSNoYesany 8-bit set: / null30Original File System 1985
Amiga FFSNoYesany 8-bit set: / null30Fast File System 1988
Amiga PFSNoYesany 8-bit set: / null107Professional File System 1993
Amiga SFSNoYesany 8-bit set: / null107Smart File System 1998
Amiga FFS2NoYesany 8-bit set: / null107Fast File System 2 2002
BeOS BFSYesYesUnicode, using UTF-8 encoding/255
DEC PDP-11 RT-11NoNoRADIX-506 + 3Flat filesystem with no subdirs. A full "file specification" includes device, filename and extension in the format: dev:filnam.ext.
DEC VAX VMSNoFrom
v7.2
A–Z 0–9 $ - _32 per component; earlier 9 per component; latterly, 255 for a filename and 32 for an extension.a full "file specification" includes nodename, diskname, directory/ies, filename, extension and version in the format: OURNODE::MYDISK:FILENAME.EXTENSION;2 Directories can only go 8 levels deep.
Commodore DOSYesYesany 8-bit set:, =$16length depends on the drive, usually 16
HP 250YesYesany 8-bit setSPACE ", : NULL CHR$6Disks and tape drives are addressed either using a label or a unit specification. The HP 250 file system does not use directories, nor does it use extensions to indicate file type. Instead the type is an attribute.

OWIKI.org. Text is available under the Creative Commons Attribution-ShareAlike License.