Managing Your 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, rename files to distinguish different versions of a file, or give several names to the same file. You may want to create new directories each time you start working on a different project.
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 sections below explain how to make and remove directories and files.
Creating Directories
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).
mkdir
To create a new directory, use the mkdir command. The format 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.dine
Copying Files
If you’re about to edit a file, you may want to save a copy of it first. Doing that makes it easy to get back the original version.
cp
The cp command can put a copy of a file into the same directory or into another directory. cp doesn’t affect the original file, so it’s a good ...
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