How to Use Bash to Create Directories in Linux with mkdir

To create a directory from Bash on Linux, use the mkdir command followed by the directory name. For example, mkdir projects creates a folder named projects inside your current working directory. You do not need a separate file manager or an extra package for normal directory creation.

Strictly speaking, mkdir is not a Bash built-in. Bash runs the directory-creation utility installed on the system; on typical GNU/Linux distributions, that utility comes from GNU Coreutils. The current GNU Coreutils mkdir documentation describes the standard syntax and useful options such as -p, -m, and -v.

Create a directory with mkdir

Open a terminal and, if necessary, use pwd to check your current location. Then run:

mkdir projects

If the command succeeds, it normally prints nothing. Confirm the new directory with:

ls
Linux terminal showing mkdir projects followed by ls with the new projects directory visible
Creating one directory in the current location with mkdir.

You can also give mkdir a path. In Bash, an unquoted ~ expands to your home directory, so this creates archives under your home folder:

mkdir ~/archives

The Bash manual on tilde expansion explains how ~ is expanded. If the parent directory does not exist, plain mkdir fails; use -p for nested paths.

Create nested directories with mkdir -p

The -p or --parents option creates missing parent directories as needed. This is the most convenient choice when you are building a deeper directory tree:

mkdir -p ~/work/client/site/assets

If work, client, or site does not exist yet, mkdir -p creates it. It also does not report an error merely because an existing path component is already a directory.

Linux terminal showing mkdir -p creating the nested path work client site assets
mkdir -p creates missing parent directories in one command.

For scripts, you can add -v when you want visible confirmation of what was created:

mkdir -pv ~/work/client/site/assets

Create several directories at once

mkdir accepts more than one directory name, so you can create multiple folders with a single command:

mkdir docs images backups

Because this guide uses Bash, you can also use brace expansion when several directory names share the same path:

mkdir -p project/{src,tests,docs}

Bash expands that expression before running mkdir, producing project/src, project/tests, and project/docs. GNU Bash documents this behavior in its brace expansion reference. Brace expansion is a Bash feature, so do not assume a script executed by a strictly POSIX sh will interpret it the same way.

Linux terminal showing mkdir -p project brace expansion creating src tests and docs directories
Bash brace expansion is a compact way to create several related directories.

Directory names with spaces and custom permissions

If a directory name contains spaces, quote the entire name when it is relative to your current directory:

mkdir "Project Files"

For a path under your home directory, using $HOME inside double quotes is safer than quoting a literal tilde:

mkdir "$HOME/Project Files"

Do not write mkdir "~/Project Files" and expect ~ to expand; quoting the tilde prevents normal tilde expansion.

GNU mkdir also supports -m for setting the new directory's permission mode. For example:

mkdir -m 750 private

That requests read, write, and execute permission for the owner, read and execute for the group, and no permissions for others. Check the result with:

ls -ld private
Linux terminal showing mkdir with a quoted directory name and mkdir -m 750 followed by ls -ld permission output
Quotes protect names with spaces, while -m sets the requested directory permission mode.

Common mkdir errors

  • File exists: the target name already exists. If it is an existing directory in a nested path, mkdir -p may be appropriate.
  • No such file or directory: a parent path is missing. Use mkdir -p path/to/new/folder when you want missing parents created automatically.
  • Permission denied: your account cannot write to that location. Create the directory somewhere you own, or use administrative privileges only when the system location genuinely requires them.
  • Spaces split the name: quote the path, for example mkdir "$HOME/My Projects".

Remove a directory you created

For an empty directory, use rmdir:

rmdir projects

The GNU Coreutils rmdir documentation confirms that rmdir removes empty directories. If a directory contains files, rmdir refuses to remove it. Recursive deletion with rm -r is available for non-empty directories, but check the path carefully first because it removes the directory and its contents.

Quick command reference

  • mkdir name — create one directory in the current location.
  • mkdir ~/name — create one directory under your home directory.
  • mkdir -p a/b/c — create a nested directory tree and missing parents.
  • mkdir one two three — create several directories at once.
  • mkdir -p project/{src,tests,docs} — use Bash brace expansion for related folders.
  • mkdir "$HOME/Project Files" — safely create a home-directory path containing spaces.
  • mkdir -m 750 private — create a directory with a specified permission mode.
  • mkdir --help or man mkdir — view local command help.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.