Managing Files
The tree structure of the Unix filesystem makes it easy to organize
your files. After you make and edit some files, you may want to copy
or move files from one directory to another, or rename files to
distinguish different versions of a file. You may want to create new
directories each time you start a different project. If you copy a
file, it’s worth learning about the subtle
sophistication of the cp and
CpMac commands: if you copy a file to a directory,
it automatically reuses the filename in the new location. This can
save lots of typing!
A directory tree can get cluttered with old files you don’t need. If you don’t need a file or a directory, delete it to free storage space on the disk. The following sections explain how to make and remove directories and files.
Creating Directories with mkdir
It’s handy to group related files in the same directory. If you were writing a spy novel, you probably wouldn’t want your intriguing files mixed with restaurant listings. You could create two directories: one for all the chapters in your novel (spy, for example), and another for restaurants (boston.dine).
To create a new directory, use the mkdir program.
The syntax is:
mkdir dirname(s)dirname is the name of the new directory. To make several directories, put a space between each directory name. To continue our example, you would enter:
$ mkdir spy boston.dineCopying Files
If you’re about to edit a file, you may want to save a copy first. That makes it easy to get back the original ...
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