Chapter 4. File Management
Chapter 3 introduced the Unix filesystem. This chapter explains how to name, edit, copy, move, find, and print files.
File and Directory Names
As 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 ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access