home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 4.7 Make More Directories! Chapter 4
Organizing Your Home Directory
Next: 4.9 Setting Up vi with the .exrc File
 

4.8 Making Directories Made Easier

In article 4.7 , we told you that you should have lots of directories. Experienced UNIX users are creating new directories all the time. How do you make a directory?

It's easy. Use the mkdir command, followed by the name of your new directory:

% 

mkdir 



directory

This creates the new directory you want. It doesn't necessarily have to be in your current directory. For example:

% 

cd /home/los/mikel


% 

mkdir /src/books/power/articles/files

The only requirements are:

  • The parent of the directory you want to create must exist (in this case, /src/books/power/articles ).

  • You must have write access to the parent directory.

mkdir
What if the parent directory doesn't already exist? Assume, for example, that /src/books already exists, but the power and articles directories don't. You can make these "by hand," or (on many UNIX systems, and with the GNU version on the CD-ROM) you can add the -p (parents) option:

% 

mkdir -p /src/books/power/articles/files

This tells mkdir to create all the intermediate directories that are needed. So the above command creates three directories:

  1. /src/books/power

  2. /src/books/power/articles

  3. /src/books/power/articles/files

[If your mkdir doesn't have -p , you can use csh or bash history ( 11.2 ) :

% 

mkdir /src/books/power


% 

!!/articles


mkdir /src/books/power/articles
% 

!!/files


mkdir /src/books/power/articles/files

That's almost as quick. -JP  ]

If you are using System V, you can also supply the "file protection mode" to be assigned to the directory. (By default, the file protection mode is derived from your umask ( 22.4 ) .) To do so, use the -m option. For example:

% 

mkdir -m 755 /src/books/power/articles/files

This creates the directory with access mode 755, which allows the owner to do anything with the directory. Note that this must be a numeric mode; see article 22.1 for an introduction to file and directory protection.

- ML


Previous: 4.7 Make More Directories! UNIX Power Tools Next: 4.9 Setting Up vi with the .exrc File
4.7 Make More Directories! Book Index 4.9 Setting Up vi with the .exrc File

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System