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
| Pattern | Avoid |
|---|---|
my-project | my project (spaces) |
data_2024 | Names starting with - |
reports | Very 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.