Making Directories Made Easier

In article , 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/tutorials/power/articles/files

The only requirements are:

mkdir What if the parent directory doesn't already exist? Assume, for example, that /src/tutorials 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 tutorial) you can add the -p (parents) option:


% mkdir -p /src/tutorials/power/articles/files

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

  1. /src/tutorials/power
  2. /src/tutorials/power/articles
  3. /src/tutorials/power/articles/files

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

% mkdir /src/tutorials/power % !!/articles mkdir /src/tutorials/power/articles % !!/files mkdir /src/tutorials/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 ().) To do so, use the -m option. For example:

% mkdir -m 755 /src/tutorials/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 for an introduction to file and directory protection.

- ML