theshell.ch/site/pages/fs/mkdir.html

58 lines
1.5 KiB
HTML
Raw Normal View History

---
layout: page
category-page: fs
category-title: FileSystem
tags: working directory current position where
author: Mirko Ponzio
title: mkdir
---
<!-- Co-authored with Alessandro Marinelli -->
The <code>mkdir</code> command is used to create new directories<br>
The name stands for <i>MaKe DIRectory</i>.<br>
The default ls command syntax is:
<pre>
mkdir [flags] [-m mode] directory_name ...
</pre>
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>
<h3>Create a new directory</h3>
Let's see how to create a new directory:
<pre>
ls
mkdir test_directory
ls
test_directory
</pre>
<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.
<pre>
mkdir -p test_directory/subdir/subsubdir
</pre>
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.