Skip to main content

mkdir: Creating Directories

mkdir (make directory) creates a new folder. Use it to organize your files into logical groups.

Basic usage

mkdir archive

Verify it was created:

ls

Output:

archive documents downloads

Directories appear in blue in the terminal (in most themes).

What happens if it already exists?

mkdir archive
# mkdir: cannot create directory 'archive': File exists

mkdir refuses to overwrite an existing directory. If you need to create a path including parents that may not exist, use mkdir -p (next lesson).

Creating directories at a specific path

mkdir /home/user/documents/2024-reports

Or relative to your current location:

mkdir documents/drafts

Naming conventions

PatternAvoid
my-projectmy project (spaces)
data_2024Names starting with -
reportsVery long names
Keep directory names lowercase

Linux and macOS are case-sensitive. Reports and reports are different directories. Lowercase avoids confusion.

Practice

Create a directory called archive in your home directory.

Loading terminal…
Donate to this project