Skip to content

Creating Directories with mkdir in Linux

Published: at 12:00 AMSuggest Changes

Table of Contents

Open Table of Contents

Introduction

The mkdir command is used to create directories in Linux. It is a fundamental command for organizing files and directories.

Basic Usage of mkdir

Syntax

The basic syntax of mkdir is:

mkdir [options] directory_name

Example

To create a directory named “new_folder”:

mkdir new_folder

Common Use Cases

  • Creating Nested Directories: Use the -p option to create parent directories as needed.
    mkdir -p parent/child/grandchild
    

Advanced mkdir Techniques

Setting Permissions

You can set permissions while creating a directory using the -m option.

mkdir -m 755 new_folder

Common Errors

  • Directory Exists: If the directory already exists, you will receive an error.
  • Permission Denied: Ensure you have the necessary permissions to create a directory in the specified location.

Conclusion

Understanding the mkdir command is essential for effective file organization in Linux.


Previous Post
Using man in Linux Commands
Next Post
Using mv in Linux Commands