Your Internet Consultant - The FAQs of Life Online

3.29. What should I know about files and directories in UNIX?

If you've used any other computer operating system, you are familiar with the concepts of files and directories. Files are individual collections of information stored on a computer (for instance, a letter to Aunt Zelda, a picture of the moon, or a game program.) Directories allow you to place files in a logical manner so that you can find them later. UNIX files and directories are very similar to those on DOS computers.

Your account has a home directory, the directory you use by default when you log on to the system. You can change your current directory, list a directory's contents, and create and remove directories that are part of your home directory. Like DOS, UNIX uses a hierarchical directory structure. This means that there is one root directory and many subdirectories in which to store files. Figure 3.1 shows what a simple directory tree might look like.


Figure 3.1. A simple directory tree.

A file in the mystuff directory can be referred to as follows:

This is referred to as the filename's full path. The first / must be there for it to be a full path. If you leave it off, UNIX will look for the file starting in your present directory. This is useful because having to constantly refer to files by their full pathnames would get tedious. If you were in waffle and wanted to refer to filename in mystuff you could call it mystuff/filename. Or if you are already in mystuff, just use filename.

If you use DOS on your home computer, note that UNIX uses a forward slash between directory names rather than a backslash.

Note: If you use DOS, you're also used to restrictive filenames with eight letters, a period, and an extender of three more letters (for example, grandmas.ltr). If you use a Macintosh, you have the luxury of filenames of up to 31 characters. Depending on what flavor of UNIX you're using, you may be allowed filenames from 14 to 255 characters. And, unlike DOS, which likes only A-Z, 0-9, and the underline in filenames, UNIX filenames can contain just about any character you can type on the keyboard. (Some characters are possible as part of a filename, like the space character, brackets, and the asterisk, but can get you in sticky situations later. It's best to avoid using them.)

Table of Contents | Previous Section | Next Section