Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

mkdir - make directories

&pagelevel(4)&pagelevel

mkdir is used to create new directories.

mkdir automatically makes the following standard entries in the new directory:

.(dot)for the directory itself
..(dot dot)for the parent directory

To be able to use mkdir you have to have write permission in the parent directory.


Syntax


mkdir[ -m modus][ -p] directory ...

No option specified

mkdir creates the named directories in mode 777 (see section “chmod change file modes”) unless the umask command has been used to change the
file creation mode mask (see section “umask get or set the file mode creation mask”).

-m mode

(mode)

The access permissions specified in mode are used for the new directory (see section “chmod change file modes”).

-p

(parent)

mkdir creates any non-existing parent directories that are given in the path name of directory before creating the directory itself.

directory

Name of the directory that you wish to create. You can also create more than one directory at a time.

directory can be given either as a relative path name or as an absolute path name.

The user ID and the group ID of the new directory are set to the real user ID and real group ID of the calling process.

Exit status

0If all directories given in the command line were made successfully.
>0If an error occurs. mkdir also prints an error message.

Locale

The following environment variables affect the execution of mkdir:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example

Creating a new directory named letters in the directory /home/sisyphus/general:
First you check which directory you are in. The default directory mode is set to 777.

$ pwd

/home/sysiphus

Next you list the contents of this directory:

$ ls -l

total 145

-rw-r--r--   1 SISYPHUS   group1      5329   Nov 03 09:54 diff.rc.1

drwx--x--x   2 SISYPHUS   group1      2589   Aug 03 15:08 general

                 .
                 .

                 .

drwxr-----   3 SISYPHUS   group1      2340   Jun 11 15:35 lingua
drwx------   2 SISYPHUS   group1      3380   Oct 11 15:36 post

drwx--x--x   2 SISYPHUS   group1      2080   Nov 04 16:08 proc

drwx------   2 SISYPHUS   group1      1560   Oct 11 15:36 screens

Then you create the new directory:

$ mkdir general/letters

Finally you check whether a directory named letters has been created:

$ cd general

$ ls -l

total 5

drwx--x--x   2 SISYPHUS   group1       520   Jan 22 16:21  letters

See also

rm, rmdir, umask