How to Create and Remove Directories with mkdir and rmdir

Published 2026-08-05 · Learn Linux

The mkdir command creates directories and rmdir removes them. mkdir projects makes a folder called projects, and rmdir old removes it if it is empty. The two flags you will use most are -p for nested paths and -m for permissions.

Create a directory

mkdir takes the folder name and creates it in the current directory. Multiple names create several folders at once.

$ mkdir projects
$ mkdir docs images backups

Create a nested path with -p

Plain mkdir fails if a parent is missing. Add -p to create every level at once. It is also a handy no-op idiom: if the folder already exists, nothing happens.

$ mkdir -p src/components/buttons

Set permissions at creation with -m

Use -m to set the mode as you create. This creates a folder that only you can read and write:

$ mkdir -m 700 secrets

The numbers follow the same system as chmod.

Remove a directory with rmdir

rmdir only removes empty directories — it refuses to delete folders with files inside. That refusal is its safety feature. Use rmdir -p to remove a path of empty directories from the deepest level up.

$ rmdir empty-folder

Remove a full directory

When a folder has contents, rmdir reports Directory not empty. To delete it and its contents, use rm -r. See mkdir and rmdir for the full references.

Keep learning

Related guides: How to Delete Files Safely with the Linux rm Command · How to Move and Rename Files with the Linux mv Command · How to Create Files and Update Timestamps with touch. Read all tutorials on the Learn Linux blog.