December 2, 2026 - 21:51
Linux Lesson 06 — mkdir: Create Directories and Nested Paths Image
Linux Tutorials

Linux Lesson 06 — mkdir: Create Directories and Nested Paths

0 Comments

We have explored existing directories. Before creating files, let us build a separate practice area so later commands have a clear home. Folder and directory refer to the same concept here.

Create a small tree

BASH
cd
mkdir netopsiyon-dersleri
cd netopsiyon-dersleri
mkdir belgeler gorseller
mkdir -p arsiv/2026/aralik
mkdir "Ders Notlari"
ls

Plain cd returns home. Mkdir creates netopsiyon-dersleri there. The name means make directory. Creating a directory does not enter it, which is why the next line uses cd.

The two unquoted names belgeler and gorseller are separate targets. The quoted name “Ders Notlari” is one target containing a space.

Make mkdir and mkdir -p behave differently

If the parent already exists, an easy first example can hide the distinction. Start inside the course directory and create a new comparison folder that has no rapor entry:

BASH
mkdir mkdir-karsilastirma
cd mkdir-karsilastirma
mkdir rapor/2026

The last command is expected to fail. Plain mkdir tries to create the requested final directory; it does not also create the missing rapor parent. A missing-path error refers to that absent route, not an invalid name for 2026.

You could explicitly create each level:

BASH
mkdir rapor
mkdir rapor/2026

Now both levels exist. Use a different name for the next experiment so we do not confuse creating something with accepting an existing tree:

BASH
mkdir -p arsiv/2026/aralik
ls -d arsiv arsiv/2026 arsiv/2026/aralik

The -p option creates missing parents as needed. The verification names all three levels, showing that the required route really exists rather than relying on silence from mkdir.

An existing directory is another important difference

BASH
mkdir rapor/2026
mkdir -p rapor/2026

The first reports an existing destination. The second succeeds when the target is already a directory. Thus -p both creates missing parents and avoids treating an existing directory as an error. Its long spelling is --parents.

This is useful for repeatable setup steps: ensuring a log directory exists should not necessarily fail just because an earlier run created it. But -p is not a universal repair option.

A regular file remains an obstacle

BASH
touch engel
mkdir -p engel/alt

Inside this disposable comparison folder, touch creates an empty file named engel. The next command must fail because a regular file cannot contain a child directory. The option neither deletes the file nor converts it into a directory. It also does not bypass filesystem permissions.

Initial statemkdir a/bmkdir -p a/b
a is absentFails.Creates a and b.
a exists, b is absentCreates b.Creates b.
a/b already is a directoryReports an existing target.Succeeds, preserving it.
a is a regular fileFails.Fails; no conversion occurs.

Show creation with -v

BASH
mkdir -pv deneme/alt/son

The -v option reports directories being created. It answers an output question, while -p controls the creation behavior. On a repeat run there may be no creation messages because nothing new was required. Return to the main practice directory afterwards so later files are not accidentally created inside the comparison folder.

Verify the location

Use pwd to confirm you are inside netopsiyon-dersleri, then inspect the results with ls -l and ls -l arsiv/2026. If this is a remote terminal, remember that the folders exist on the remote machine, not automatically on your Windows desktop.

Create denemeler/birinci with -p, enter it with cd and check with pwd. Creation, navigation and verification are separate operations; identify the command responsible for each.

Previous lesson · Next lesson

References: GNU / Linux

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment