File Naming Conventions in Linux

A file name, also called a filename, is a string (i.e., a sequence of characters) that is used to identify a file.

A file is a collection of related information that appears to the user as a single, contiguous block of data and that is retained in storage, e.g., a hard disk drive (HDD), floppy disk, optical disk or magnetic tape. Names are given to files on Unix-like operating systems to enable users to easily identify them and to facilitate finding them again in the future.

However, file names are only a convenience for users, and such operating systems identify files by their inodes, which are numbers that are stored on the HDD in inode tables and which exist for all types of files, rather than by their names or locations in directories.

This is somewhat analogous to the domain names that are used on the Internet to identify web sites. The names are only for the convenience of human users of the system, and each site is identified by the network by a set of numbers referred to as an IP address.

File names in Linux can contain any characters other than (1) a forward slash ( / ), which is reserved for use as the name of the root directory (i.e., the directory that contains all other directories and files) and as a directory separator, and (2) the null character (which is used to terminate segments of text). Spaces are permitted, although they are best avoided because they can be incompatible with legacy software in some cases.

Typically, however, file names only use alphanumeric characters (mostly lower case), underscores, hyphens and periods. Other characters, such as dollar signs, percentage signs and brackets, have special meanings to the shell and can be distracting to work with. File names should never begin with a hyphen.

A relatively small number of file names on a system consist only of upper case characters, such as README, INSTALL, NEWS and AUTHORS. They are usually plain text files that come bundled with programs and are for documentation purposes.

File names were limited to 14 bytes (equivalent to 14 characters) in early UNIX systems. However, modern Unix-like systems support long file names, usually up to 255 bytes in length. File names can be as short as a single character.

In some operating systems, such as MS-DOS and the Microsoft Windows systems, file names consist of two parts: a user-designated name and an extension which is determined by the type of file. The two are separated by a period.

Although Unix-like operating systems generally do not require the use of file extensions, they can be convenient and useful. In particular, they can make it easy to identify file types at a glance and to facilitate manipulating groups of files. Files can also have multiple extensions, such as ghex-2.6.0.tar.gz.

File names must be unique within a directory. However, multiple files and directories with the same name can reside in different directories because such files will have different absolute pathnames (i.e., locations relative to the root directory), and thus the system will be able to distinguish them.

In Unix-like operating systems, directories are just a special type of file, and thus their naming conventions are similar to those for ordinary files. The major exception is the root directory, whose name is always a forward slash.

In documentation, it is usually sufficient to refer to files and directories by their names rather than by their absolute pathnames. However, the first tier of directories in the root directory are usually referred to by their absolute pathnames, e.g., /bin, /boot, /etc, /home and /usr.

There are several ways to change the name of a file or directory. One is to use the mv (i.e., move) command. Thus, for example, to change the name of a file named file1 to file2, the following would be used:

mv file1 file2

When working in a GUI (graphical user interface), a name can be changed by using the right mouse button to click on an icon (i.e., small image) representing a file or a directory and selecting the Rename item in the menu that appears. The cursor is moved to the label for that item and the new name can then be typed in.

On a Unix-like operating system any file or directory can have multiple names because of the operating system's use of inodes instead of names to identify files and directories. Additional names can be provided by using the ln command to create one or more hard links to a file or directory.

Created July 21, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.