Intro to Unix

Unix File Names

The purpose of this short lesson is to introduce you to how files (and directories) are named in Unix.

As we saw in the lesson on the Unix file system, Unix keeps track of files and directories of files using a file system.

The names that you come up with for your Unix files need to work within this file system. The way you name files in Unix is pretty flexible, but there are specific rules you have to follow. In practice, there are also some good habits to get into when making your own files.

Unix File Naming Rules

Although some Unix systems might vary, the general rules for file naming are as follows.

You can name a file in Unix using up to a certain number of characters (the precise number is defined by your particular Unix installation--check your system documentation) in any combination from the following sets:

  1. {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z}
  2. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  3. {period (.), underscore(_), comma(,)}

You can not name a file period (.) or period period (..).

Directories are files in Unix, so directory names follow these same rules also.

Unix File Naming Practices

You need to follow the official rules for file naming in Unix, but here are some good practices that I've found also help keep things straight:

  1. Avoid naming a file with the same name as a Unix command. You can find out if a name is a Unix command by using the man command.
  2. Use file extensions that are widely recognized when possible. For example, if you create a text file, use the character string .txt as the last part of the file name.
  3. Make all the letters of all your files (and directory names) lower case. Unix cares about case. That is, the file Alpha.txt is different from alpha.txt. A the capital letter is only going to cause you problems with trying to remember if the filename or directory name has a capital letter or not. Simply use all lower case. It makes life easier.
  4. Start a file name with a letter or number. If you start it with a dot (.), it will be a hidden file.
  5. Make your names short, but not cryptic. Use correctly-spelled nouns when possible. For example, store your inventory in inventory.dat and not invtry.dat.

Exercise: Make up some file names

Create some files in your home directory with a variety of names.

Then write out the absolute pathnames of these files.

search Search · star Market
2023-06-01 · John December · Terms ©