How to use the mkdir command on Linux to create folders

11 set 2024 2 min di lettura
How to use the mkdir command on Linux to create folders
Indice dei contenuti

Introduction

In Linux, efficient folder management is essential to organize and manage files in a structured way. One of the most basic yet essential tools for this purpose is the mkdir command. This tutorial will guide you through the essential steps to use mkdir to create new folders. You will learn how to configure and use mkdir effectively, with practical examples and code snippets.

What is mkdir ?

mkdir is a Linux utility command that allows you to create new folders (directories) on your system. Unlike other tools, mkdir is known for its simplicity and its ability to handle the creation of single or multiple folders. This makes it ideal for basic tasks such as creating directory structures for projects, backups, or archives.

Basic usage of mkdir

The mkdir command has a relatively simple syntax. Here is a basic example of creating a new directory:

mkdir nome_della_cartella

Practical example: creating a folder

Let's say we want to create a new folder called Progetto in the current folder. Here's how to do it:

mkdir Progetto

Create folders in different paths

You can also use mkdir to create folders in different paths by specifying the full path to the folder.

Practical example: creating a folder in a different path

Let's say we want to create a new folder called Backup in the /home/utente/Documenti folder. Here's how to do it:

mkdir /home/utente/Documenti/Backup

Create multiple folders at once

mkdir also allows you to create multiple folders at once by specifying folder names separated by spaces.

Practical Example: Creating Multiple Folders at Once

Let's say we want to create three folders called Cartella1, Cartella2, and Cartella3. Here's how to do it:

mkdir Cartella1 Cartella2 Cartella3

Creating folders with recursive structure

If you want to create a recursive folder structure, you can use the -p (parents) option. This option automatically creates all the necessary intermediate folders.

Practical Example: creating a recursive folder structure

Let's say we want to create a folder structure that includes Progetti/Lavoro/2023. Here's how to do it:

mkdir -p Progetti/Lavoro/2023

Creating folders with explicit permissions

You can also specify permissions for new folders using the -m (mode) option. This option allows you to set permissions in octal format.

Practical example: creating a folder with explicit permissions

Suppose we want to create a new folder called Sicurezza with read, write, and execute permissions for the owner, and read and execute only for the group and others. Here's how to do it:

mkdir -m 755 Sicurezza

Conclusion

mkdir is an essential tool for anyone working with files and folders on Linux. Due to its simplicity and versatility, mkdir has become a standard for creating new folders. By following this tutorial, you should be able to use mkdir to handle your folder creation needs effectively and safely.

Always remember to test commands in a safe environment before applying them in production, and to be careful about paths and options used to avoid creating unwanted folders. With mkdir, managing your folders becomes a simple and reliable operation.

Support us with a

Successivamente, completa il checkout per l'accesso completo a Noviello.it.
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a Noviello.it.
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.