There are many ways to create files and directories from the command line. The method you choose depends on your purpose. Two common purposes are to capture the output of a command into a file, and to create a new, empty directory. Chapter 6 covers the more complex tasks of editing files from the command line, but we'll go over the basics here. To create a new directory:
Tip
Figure 5.20. Use the ls command to check that mkdir really created a directory. (What you see will be different.)localhost:~ vanilla$ ls Current Projects Library Pictures bin Desktop Movies Public system-status Documents Music Sites localhost:~ vanilla$ mkdir "My Projects" localhost:~ vanilla$ ls Current Projects Library My Projects Sites Desktop Movies Pictures bin Documents Music Public system-status localhost:~ vanilla$ To create a series of nested directories:
To create an empty file:
Creating a file from command outputThe output of most commands can be sent into a file instead of your screen by adding > path/to/file at the end of the command line. If the file already exists, the old contents are replaced . Use >> to append or create instead of replacing the old contents. (Review the section "To save output in a file" in Chapter 2.) |