0
0
Linux CLIscripting~3 mins

mkdir (create directories) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Creating folders on your computer helps you organize files. The mkdir command makes new folders quickly from the command line.
When you want to organize your project files into separate folders.
When you need to create a folder to save downloads or documents.
When setting up a new workspace for coding or writing.
When automating folder creation in scripts for backups or logs.
When preparing directories before moving or copying files.
Commands
This command creates a new folder named 'my-folder' in the current directory.
Terminal
mkdir my-folder
Expected OutputExpected
No output (command runs silently)
Creates nested folders 'projects/python/scripts' all at once. The -p flag makes parent folders if they don't exist.
Terminal
mkdir -p projects/python/scripts
Expected OutputExpected
No output (command runs silently)
-p - Create parent directories as needed
Lists files and folders in the current directory to verify the new folders were created.
Terminal
ls -l
Expected OutputExpected
total 0 drwxr-xr-x 2 user user 4096 Jun 10 12:00 my-folder drwxr-xr-x 3 user user 4096 Jun 10 12:01 projects
-l - Show detailed list with permissions and timestamps
Key Concept

If you remember nothing else from mkdir, remember: use -p to create nested folders in one step without errors.

Common Mistakes
Trying to create nested folders without -p flag like mkdir projects/python/scripts
mkdir fails if parent folders don't exist, so nested folders won't be created.
Use mkdir -p projects/python/scripts to create all needed folders at once.
Using mkdir with a folder name that already exists
mkdir returns an error because it won't overwrite existing folders.
Check if the folder exists first or use mkdir -p which ignores existing folders.
Summary
mkdir creates new folders to organize files.
Use mkdir folder-name to make a single folder.
Use mkdir -p path/to/folder to create nested folders in one command.