Creating Directories with mkdir

by mike on November 28, 2011

mkdir
Use this command to create new directories. There aren’t a lot of options for it, so it’s quite easy to use.

To create one directory, which we’ll call “data”, enter:

mkdir data

Use the “-m” switch to create the new directory with other than the default permissions. Here, create a directory with a permissions setting of “771″

mkdir -m771 db_data

You aren’t limited to just creating one directory at a time. Here, use a string-type wildcard to create several “data_” directories with different endings
for their names.

mkdir data{_01,_02,_03,_for_my_stuff}

Use “-p” to create multiple levels of directories with one command.

mkdir -p /var/vmail/example.com/user/new

Add the “-v” switch, and mkdir will show you the list of directories that it’s created.

mkdir -vp /var/vmail/example.com/user/new

This also works if you’re just creating a single directory.

mkdir -v oracle_data mkdir: created directory `oracle_data'

The Linux command for making a single directory is mkdir. It is a simple command that allows you to create a directory by listing the name that you want.

mkdir data

That works fine until you decide that you want to create multiple directories at the same time. By separating the directories that you would like to
create with spaces, multiple directories can be created.

mkdir oracle_db mysql_db postgresql_db

Directories can be created several deep by using the -p option which will then create multiple directories deep, note that the names are separated by a “/”.

mkdir -p db/mysql/data_1/data_2

Comments on this entry are closed.

Previous post:

Next post: