1.11. Filenames
Like all operating systems, Unix
files have names. (Unix directories, devices, and so on also have
filenames -- and are treated like
files (Section 1.19).) The names are words
(sequences of characters) that let you identify a file. Older
versions of Unix had some restrictions on the length of a filename
(14 characters), but modern versions have removed these restrictions
for all practical purposes. Sooner or later you will run into a
limit, but if so, you are probably being unnecessarily verbose.
Technically, a filename can be made
from almost any group of characters (including nonprinting characters
and numbers) except a slash (/). However, you
should avoid filenames containing most punctuation marks and all
nonprinting characters. To be safe, limit your filenames to the
following characters:
- Upper- and lowercase characters
-
Unix filenames are always case sensitive. That
is, upper- and lowercase letters are always different (unlike
Microsoft Windows and others that consider upper- and lowercase
letters the same). Therefore, myfile and
Myfile are different files. It is usually a bad
idea to have files whose names differ only in their capitalization,
but that's your decision.
- Underscores (_)
-
Underscores are handy for separating
"words" in a filename to make them
more readable. For example, my_long_filename is
easier to read than mylongfilename.
- Periods (.)
-
Periods are used by some programs (such as the C compiler) to
separate filenames from filename
extensions (Section 1.12). Extensions are
used by these programs to recognize the type of file to be processed,
but they are not treated specially by the shell, the kernel, or other
Unix programs.
Filenames that begin with a period are treated specially by the
shell: wildcards won't
match (Section 1.13) them unless you
include the period (like .*). The
ls command, which lists your files, ignores files
whose names begin with a period unless you give it a special option
(ls -a (Section 8.9)). Special configuration files are often
"hidden" in directories by
beginning their names with a period.
- Certain other punctuation
-
About the only other punctuation mark that is always safe is the comma (,),
although it isn't part of the POSIX-portable
character set.
I'm so dead-set
against using weird, nonprinting characters in filenames that I
won't even tell you how to do it. I will give you
some special techniques for deleting files with
weird names (Section 14.11), though, in
case you create some by accident.
Some things to be aware of:
-
Unix does not have any concept of a file
version. There are some revision control programs (Section 39.4) that implement their own notion of a version,
but there is nothing built into the operating system that handles
this for you. If you are editing a file, don't count
on Unix to save your previous versions -- you can program this (Section 35.16,
Section 18.14) though, if you want to; the GNU Emacs
editor also makes backups (Section 19.4).
-
Once
you delete a file in Unix, it is gone
forever (Section 14.3). You
can't get it back without restoring it from a
backup. So be careful when you delete files. Later,
we'll show you programs that will give you a
"grace period" between the time you
delete a file and the time it actually disappears.
-- ML
| | | 1.10. The Kernel and Daemons | | 1.12. Filename Extensions |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|
|