Chapter 4. File ManagementContents:
File and Directory Names Chapter 3 introduced the Unix filesystem. This chapter explains how to name, edit, copy, move, find, and print files. 4.1. File and Directory NamesAs Chapter 3 explains, both files and directories are identified by their names. A directory is really just a special kind of file, so the rules for naming directories are the same as the rules for naming files. Filenames may contain any character except /, which is reserved as the separator between files and directories in a pathname. Filenames are usually made of upper- and lowercase letters, numbers, "." (dots), and "_" (underscores). Other characters (including spaces) are legal in a filename, but they can be hard to use because the shell gives them special meanings. So we recommend using only letters, numbers, dots, and underscore characters. You can also use "-" (dashes), as long as they aren't the first character of a filename, which can make a program think the filename is an option. If you have a file with a space in its name, the shell will be confused if you type its name on the command line. That's because the shell breaks command lines into separate arguments at the spaces. To tell the shell not to break an argument at spaces, put quote marks (") around the argument. For example, the rm program, covered later in this chapter, removes files. To remove a file named a confusing name, the first rm command, which follows, doesn't work; the second one does: $ ls -l total 2 -rw-r--r-- 1 jpeek users 0 Oct 23 11:23 a confusing name -rw-r--r-- 1 jpeek users 1674 Oct 23 11:23 ch01 $ rm a confusing name rm: a: no such file or directory rm: confusing: no such file or directory rm: name: no such file or directory $ rm "a confusing name" $ Unlike some operating systems, Unix doesn't require a dot (.) in a filename; in fact, you can use as many as you want. For instance, the filenames pizza and this.is.a.mess are both legal. Some Unix systems limit filenames to 14 characters. Most newer systems allow much longer filenames. A filename must be unique inside its directory, but other directories may have files with the same names. For example, you may have the files called chap1 and chap2 in the directory /users/carol/work and also have files with the same names in /users/carol/play. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|