2018-11-12 09:07:41 +00:00
|
|
|
---
|
|
|
|
layout: page
|
2018-11-14 13:28:12 +00:00
|
|
|
category-page: fs
|
|
|
|
category-title: FileSystem
|
2018-11-15 08:26:58 +00:00
|
|
|
tags: working directory current position where
|
2018-11-12 09:07:41 +00:00
|
|
|
author: Mirko Ponzio
|
2018-11-12 10:47:50 +00:00
|
|
|
title: mkdir
|
2018-11-18 20:38:56 +00:00
|
|
|
previous-page: pages/fs/ls.html
|
|
|
|
next-page: pages/fs/mv.html
|
2018-11-12 09:07:41 +00:00
|
|
|
---
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<!-- Co-authored with Alessandro Marinelli -->
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
The <code>mkdir</code> command is used to create new directories<br>
|
|
|
|
The name stands for <i>MaKe DIRectory</i>.<br>
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
The default ls command syntax is:
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
|
|
|
mkdir [flags] [-m mode] directory_name ...
|
|
|
|
</pre>
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Where [flags] are the mkdir <code>-p</code> and <code>-v</code> - flags,
|
|
|
|
read below for more info, and <i>directory_name</i> is the
|
|
|
|
name of the new directory we are going to create.<br><br>
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<h3>Create a new directory</h3>
|
|
|
|
Let's see how to create a new directory:
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
|
|
|
ls
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
mkdir test_directory
|
|
|
|
ls
|
|
|
|
test_directory
|
|
|
|
</pre>
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<h3>Create a path of directories</h3>
|
|
|
|
Using the flag <code>-p</code> we can create a path of directories, allowing us
|
|
|
|
to build more than a directory at once.
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
|
|
|
mkdir -p test_directory/subdir/subsubdir
|
|
|
|
</pre>
|
2018-11-12 09:07:41 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
As you can see, we are now creating two directories: one named <i>subdir</i> and
|
|
|
|
another one, included in this, named <i>subsubdir</i><br>
|
|
|
|
The -p flag is necessary to allow the shell to create intermediate
|
|
|
|
directories as required.<br><br>
|
|
|
|
|
|
|
|
<h3>Create directories with specified permissions</h3>
|
|
|
|
The <code>-m mode</code> option allows us to set permissions at the new directory
|
|
|
|
that we are now creating.
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
mkdir -m 777 test_free_directory
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
Our new directory will now have read,write and execute permissions for user, group and others.
|