[Previous] [Contents] [Next]

mkdir

Make directories (POSIX)

Syntax:

mkdir [-m mode] [-p] [-s size] dir...

Options:

-m mode
When creating the directory, set the file permission bits of the new directory to the specified mode value.

The mode argument is a symbolic_mode string, as defined for the chmod utility. In the symbolic_mode strings, the op characters + and - are interpreted relative to the default file mode for that file type:

+
add permissions to the default mode
-
delete permissions from the default mode
=
assign permissions
-p
Create any missing intermediate pathname components.
-s size
Create the directory with the given initial size (where the size is the number of entries a directory will hold before it has to be grown). This will reduce the number of filesystem extents a file will occupy if it is filled with a large number of files. Note that large directories should generally be avoided since they will increase the time it takes to open a file in that directory (and in particular, the time it takes to create a new file) since the filesystem will have a larger directory to scan when looking up the file by name.
dir
A pathname at which a directory is to be created.

If you specify both the -p and -m options, any intermediate directories you have created have mode u+wx.

Description:

The mkdir utility creates the directories specified by the dir operands, in the order the dir operands are specified.

To create a directory you must have write permission on the parent directory, or be root.

The default file mode for directories is a=rwx (777), with selected permissions removed in accordance with the file mode creation mask (see the umask utility).

For intermediate pathname components created by mkdir, the mode is the default modified by u+wx so that the subdirectories can always be created regardless of the file mode creation mask. If you want to assign different ultimate permissions for the intermediate directories, you can do so with the chmod utility.

When using -p with -m, each intermediate directory that doesn't exist is created with u+wx modes, regardless of the file mode creation mask. The specified mode applies only to the last directory specified. For example:

    mkdir -p -m 777 dir/dir1/dir2

would give dir and dir1 the default permissions for intermediate directories (namely, u+wx). The directory dir2 is given a+rwx permission.


Note: The default file creation mask influences the behavior of mkdir.

Examples:

Create a directory named /home/debbie:

    mkdir /home/debbie

Signals:

If the mkdir utility is terminated by a signal, some of the specified directories may have already been created.

Exit status:

0
All the specified directories were created successfully, or the -p option was specified and all the specified directories now exist.
>0
An error occurred.

See also:

chmod, rmdir, umask


[Previous] [Contents] [Next]