home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 1.14 The Kernel and Daemons Chapter 1
Introduction
Next: 1.16 Wildcards
 

1.15 Filenames

Like all operating systems, UNIX files have names: words (sequences of characters, whatever) 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 non-printing characters) except a slash (/ ). However, you should avoid filenames containing most punctuation marks and all non-printing characters. These will usually be a pain. To be safe, limit your filenames to the following characters:

  • Uppercase and lowercase characters. UNIX is always case-sensitive. That is, uppercase and lowercase letters are always different (unlike DOS and VAX/VMS, which consider uppercase 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 (1.17 ) . 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 (1.16 ) 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 (16.11 ) ). 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. The other punctuation marks may have special meanings in one situation or another. Stay away from them, or you will create filenames that are inconvenient to work with.

I'm so dead-set against using weird, non-printing 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 (23.11 ) , 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 (20.12 ) that implement their own notion of a version, but there is nothing analogous to VAX/VMS's version number. If you are editing a file, don't count on UNIX to save your previous versions - you can make scripts to do this (44.11 ) though, if you want to; the GNU Emacs editor also makes backups (32.4 ) .

  • Once you delete a file in UNIX, it is gone forever (23.2 ) . You can't get it back without restoring it from a tape. Be careful when you delete files. Later, we'll show you programs (23.8 , 23.9 ) that will give you a "grace period" between the time you delete a file and the time it actually disappears.

- ML


Previous: 1.14 The Kernel and Daemons UNIX Power Tools Next: 1.16 Wildcards
1.14 The Kernel and Daemons Book Index 1.16 Wildcards

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System