create new directory linux

"Effortlessly Create New Directories on Linux: A Step-by-Step Guide"

By John Anderson
AD

Creating a New Directory in Linux: A Comprehensive Guide

Linux, with its robust file system and user-friendly commands, makes it a breeze to create new directories. Whether you're a seasoned Linux user or just starting out, this guide will walk you through the process step by step.

Understanding Linux Directory Structure

Before we dive into creating new directories, let's briefly understand the Linux directory structure. Linux follows a hierarchical file system, with the root directory (/) at the top. The root directory contains subdirectories, which in turn contain their own subdirectories and files. Understanding this structure will help you create directories in the right location.

Creating a New Directory

To create a new directory in Linux, you'll use the `mkdir` command. Here's the basic syntax:

AD
mkdir – Make Directory in Linux
mkdir – Make Directory in Linux
Create directories on Linux using mkdir
Create directories on Linux using mkdir
Linux Commands Cheat Sheet (Day 8): touch, mkdir, tree Explained with Examples - Day 8
Linux Commands Cheat Sheet (Day 8): touch, mkdir, tree Explained with Examples - Day 8

mkdir [options] directory_name

For example, to create a new directory named `my_new_dir` in the current directory, you would type:

Learn Linux from Beginner to Advanced (Part-2) | File & Directory Commands Cheat Sheet
Learn Linux from Beginner to Advanced (Part-2) | File & Directory Commands Cheat Sheet
How to Create Directory in Linux with the mkdir Command
How to Create Directory in Linux with the mkdir Command
🔗 ln – Create Link to File and Directory in Linux
🔗 ln – Create Link to File and Directory in Linux

mkdir my_new_dir

Creating Multiple Directories at Once

You can also create multiple directories at once using a single command. To create a directory tree, use the `-p` option:

AD

mkdir -p dir1/dir2/dir3

Linux Directory structure explained : A reference guide
Linux Directory structure explained : A reference guide
useradd – Add a New User in Linux
useradd – Add a New User in Linux
Navigating Linux Directory Tree
Navigating Linux Directory Tree
Files and Directories Manipulation
Files and Directories Manipulation
Linux file directory
Linux file directory
Create directories or folders in Linux with mkdir command
Create directories or folders in Linux with mkdir command

This command will create `dir1`, then `dir2` inside `dir1`, and finally `dir3` inside `dir2`, if they don't already exist.

Changing Permissions and Ownership

By default, the new directory will have permissions set to `rwxr-xr-x` (read, write, execute for the owner, and read, execute for the group and others), and the owner will be the user who created the directory. You can change these settings using the `chmod` and `chown` commands respectively.

AD

Changing Permissions

To change permissions, use the `chmod` command. For example, to give the owner read, write, and execute permissions, and give the group and others only read and execute permissions, you would use:

How to Make a New Directory and Change to It with a Single Command in Linux
How to Make a New Directory and Change to It with a Single Command in Linux
FILE AND DIRECTORY MANAGEMENT
FILE AND DIRECTORY MANAGEMENT
How to Create Roaming Home Directories in Linux with IdM - Make Tech Easier
How to Create Roaming Home Directories in Linux with IdM - Make Tech Easier
the linux directory guide is shown in black and white, with arrows pointing to different locations
the linux directory guide is shown in black and white, with arrows pointing to different locations
the dnsrecon poster shows how to use it for programming and web development
the dnsrecon poster shows how to use it for programming and web development
How to Create and Extract Zip Files to Specific Directory in Linux
How to Create and Extract Zip Files to Specific Directory in Linux
How to Create Multiple Files and Directories at Once in a Linux Terminal
How to Create Multiple Files and Directories at Once in a Linux Terminal
Linux File System Explained – Complete FHS Directory Guide
Linux File System Explained – Complete FHS Directory Guide
How To Manage Directories in Linux With RMDIR and MKDIR
How To Manage Directories in Linux With RMDIR and MKDIR
Knowledge 22102024
Knowledge 22102024
Learn Linux from Beginner to Advanced (Part-1) | Essential Terminal Commands Cheat Sheet
Learn Linux from Beginner to Advanced (Part-1) | Essential Terminal Commands Cheat Sheet
4 ways to create a directory in Linux (and what each one teaches you)
4 ways to create a directory in Linux (and what each one teaches you)
Gogo - Create Shortcuts to Directory Paths in Linux
Gogo - Create Shortcuts to Directory Paths in Linux
5 Tools to Create Your Own Linux Distro
5 Tools to Create Your Own Linux Distro

chmod u=rwx,g=rx,o=rx my_new_dir

Changing Ownership

To change the owner of the directory, use the `chown` command. For example, to change the owner to the `www-data` user, you would use:

AD

chown www-data:www-data my_new_dir

Deleting Directories

To delete a directory, use the `rmdir` command. However, `rmdir` only works on empty directories. To delete a directory and all its contents, use the `rm` command with the `-r` option:

rm -r my_new_dir

Warning: Be careful when using the `rm` command with the `-r` option, as it will delete all files and directories inside the specified directory without asking for confirmation.

Conclusion

Creating, managing, and deleting directories in Linux is a fundamental task that every user should be comfortable with. With the commands and options outlined in this guide, you should now be able to navigate the Linux file system with ease.

AD