What's in a Name

The Unix operating system does not have any particular preference for the names you give to files and directories. The file names can be arbitrarily long (within reason), they can contain spaces and special characters, with the exception of "/", and they don't have to have any particular suffix attached to them. This gives a great deal of flexibility in the naming of files that lets the user choose names to organize his or her work.

There is one directory name and one file name which many Bama users are already familiar with. They are "public_html" and "index.html", respectively. All Bama users are given this directory when their account is created. It is not there for Unix, it is there for the web server. All their web material should be placed in this directory or in subdirectories below it. The file "index.html" is known to the web server as the file name to look for when none is specified by the browser. Therefore, it is the ideal name for one's home page.

Well, with all this flexibility in names, there are some guidelines that make Unix life easier. These are:

Don't make names too long. When you list files on the screen, Unix will divide the listing into as many columns as it can. If you have long file names then there will be fewer columns and you will fit less per screen. Also, there are times when you must refer to a file name by its full path. If the directory names leading to the file are all quite long, the resulting path name is very long and may exceed some system or program limit for the length of a string.

Don't start file names with a period unless you really mean it. In Unix, file names that start with a period are called hidden files. They normally do not appear when you do the " ls " command. You must use " ls -a" instead, to see them. These file and directory names, then, are usually used for initialization files, like ".profile" that one doesn't need to see on a day-to-day basis. Examples include:

Directory or file

Purpose

. (period)

The current directory

.. (period period)

The directory one level back

.profile

In Korn shell - executed at startup

.sh_history

In Korn shell - a history of your commands

.pinerc

Pine initialization file

.addressbook

Pine email address listings

.newmail

Incoming mail folder

.plan, .project

Plan and project shown by finger command

The examples in this table may or may not already exist. Some of them are also not directly readable or are confusing to read and were created by a program so it is advised that you work with them through that program (e.g. pine creates .pinerc and .addressbook).

Don't use file name metacharacters (also known as wildcards) and other special characters. Some characters have "wild card" attributes. These are called metacharacters and include "*", "?", "+", "@", "!", "[" and "]". Other special characters have special meanings, such as ";", which denotes the separation between commands on a multi-command line. When these characters get into file names, as they can by accident, they disturb the usual interpretation of the file name and make it difficult to work with the file. The list of problematic characters is: "; & ( ) | < > * ? [ ] ~ + @ ! \", and the quotes themselves, " " and .

Do use descriptive names, separating words with the period, the underscore character, or the hyphen. You may use as many periods or hyphens in your file name as you like.

Do use suffixes that your program expects. Some programs do have predetermined suffixes that they want to see on files. The Fortran compilers want ".f" or ".f90", the c compilers want ".c", "make" wants all the correct programming language suffixes, and the TeX text formatter wants ".tex". The Web server wants ".html" or, for server-side includes, ".shtml". Scripts for CGI programming (for the Web) want ".pl" for Perl or ".cgi" for other types of scripts or executables.

Do use suffixes that give you some hint as to content: Useful suffixes might be ".txt" for a plain text file, ".pl" for a perl script, ".spss" or ".sas" for SPSS or SAS programs, respectively, ".data" for data, and so on.

Occasionally, one would like to determine the content of a file without trying to look at it with an editor. There is a command, called "file" that is able to determine content. An example would be

file *

which would list the content type of all files and subdirectories in a directory. The results might look like this:

elephant.gif: GIF file, v89 
onet: directory 
test: executable shell script 
tplist: ascii text 

where the file or directory name is given, then its contents.

Take heart if you have included a character with special meaning in a file name and find that you cannot access the file due to some funny interpretation of the character. If often works to simply surround the filename in quotation marks. Another trick is to refer to the filename using the wildcard character, "*", to get the file renamed to something more usable. Note that it is also quite possible to get a non-printing character into a filename, although this is a rare accident. If it happens to you, you may think you are typing the filename correctly, but it will not be accepted. The trick to use in this case is to insert a wildcard character to help gloss over the bad character. So if your file is named "my.favorite.movies" and you don't know where the bad character is, try using the command

mv my* new.file.name

where "new.file.name" is chosen by you. If there are no other files beginning with "my", this should work fine.

File and subdirectory names do have to be unique within a directory but can be repeated in different directories. So that a file named test.data which is located under /fs/myuserid/Monday_results is a different file from one named test.data which is located under /fs/myuserid/Tuesday_results

 

© 1998, The University of Alabama. The information included here is for the University of Alabama central computing facility as it was configured on the document date. It may or may not apply to other Unix systems.