Module 54 FILENAMES AND FILENAME GENERATION

Previous Table of Contents Next


Module 54
FILENAMES AND FILENAME GENERATION

DESCRIPTION

This module describes filenames and special characters used for filename generation. It is important to understand file naming conventions and how to use them before learning filename generation techniques.

A filename is a string of characters representing an ordinary file, a directory file, or a special file. No matter what type of file is referenced, a filename will be used to access the file.

When naming files, use meaningful filenames. It is important to know what is in each file. By using meaningful filenames you will be able to select the file you need by viewing a list of filenames. Unfortunately, the more files you have the more difficult it becomes to keep these filenames meaningful.

At some point you will want to make subdirectories that have meaningful names . You can store related files in the proper subdirectories. It is advisable to do this when you first begin using UNIX. If you plan on having a large number of files that are related , you may want to write shell scripts that control the files for you.

For example, you name all files with a three-digit filename. Inside each file place a unique string, such as @(#), followed by a description of the file. Then use the grep command to generate a listing of the filenames and their related description. If you use the @(#) string, the what command will perform this listing function for you.

The UNIX system has de facto standards for special files and has many commands you should be aware of before naming one of your shell scripts the same name. To check for existing programs use the whence or find command as follows :

 cj> whence command                    # see if command exists in your PATH   cj> find / -name file -print > TMP &  # search entire system for file 

The use of the find command is not advisable on systems with large amounts of disk.

Filename Extensions

The UNIX system also has de facto standards for filename extensions. Most extensions are one character long. Although the period (.) does not have any special meaning in a filename, except in the first position, it is used for convention. These are not hard and fast rules of UNIX, although some programs require the proper extensions. The following list provides a brief description of each extension.


Filename Extensions

.a Assembler progamming language source code file
.c C programming language source code file
.f Fortran progamming language source code file
.o A compiled object file
.h C programming language header file
.sh Shell programming language source code file
.z A packed file

File Naming Rules

You may name your directories and files any name you wish as long as you remember the following rules.

1.    The name must be from one to 256 characters. Extra characters are ignored by the system. Keep filenames meaningful but short.
2.    All characters are legal except for the slash (/). It is used to separate directory levels and files.
3.    It is advisable to avoid the following list of characters since they are interpreted by the shell and other programs:
@ # $ ^ & * ? ( ) [ ] { } / \ ; < >
Space Tab Esc Ctrl-Characters
Spaces and tabs must be quoted if used as part of filenames.
4.    A period (.) at the beginning of a filename hides it from normal ls type referencing.
5.    Uppercase and lowercase characters are interpreted as different characters. A file named TMP is different from a file named tmp.
6.    It is advisable not to use any of the following characters at the beginning of a filename:
= + “ = _

NOTE:    
Releases of System V prior to Release 4 only support filenames of 14 characters.

FILENAME GENERATION

Filename generation provides a shorthand for referencing files and directories. The shell scans each word of the command line for filename generation characters. For every one of these characters the shell attempts to expand it to a list of matching file and directory names based on the criteria in the following wildcard section. If no matches are found then no expansion of the word is done.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net