From the Linux terminal, creating a folder is as simple as typing `mkdir` followed by your desired folder name. If you’re wondering how to create a folder in linux terminal, you’ve come to the right place. This guide walks you through every step, from basic commands to advanced options, so you can manage directories like a pro.
Linux terminal might seem intimidating at first, but creating folders is one of the easiest tasks. You don’t need a graphical interface—just a few keystrokes. Let’s start with the essentials and build up your skills quickly.
How To Create A Folder In Linux Terminal
The core command is `mkdir`, short for “make directory.” It’s available on every Linux distribution. Here’s the basic syntax:
mkdir folder_name
Replace `folder_name` with whatever you want to call your new directory. For example, to create a folder called “projects,” type:
mkdir projects
Press Enter, and the folder appears in your current location. That’s all there is to it. But there’s more to learn—like creating multiple folders at once, nested directories, and handling spaces in names.
Creating A Single Folder
Open your terminal. Navigate to where you want the folder (use `cd` to change directories). Then run:
mkdir my_folder
Check it with `ls` (list files). You’ll see `my_folder` appear. Simple, right? No confirmation message means success—Linux stays quiet unless something goes wrong.
Creating Multiple Folders At Once
Need several folders? List them after `mkdir`, separated by spaces:
mkdir folder1 folder2 folder3
This creates three folders in one command. You can mix names, numbers, or even use underscores. For example:
mkdir docs images backups
All three appear instantly. This saves time when setting up project structures.
Creating Nested Folders With -P
What if you want a folder inside another folder that doesn’t exist yet? Use the `-p` flag (parents). For instance, to create `projects/2025/reports` in one go:
mkdir -p projects/2025/reports
The `-p` flag creates any missing parent directories automatically. Without it, you’d get an error if `projects` or `2025` didn’t exist. This is perfect for deep folder trees.
Creating Folders With Spaces In Names
Spaces in folder names require special handling. Either quote the name or escape the space with a backslash:
mkdir "my documents"
or
mkdir my\ documents
Both create a folder called “my documents.” Avoid spaces if possible—they complicate commands later. Use underscores or hyphens instead (e.g., `my_documents`).
Creating Folders With Specific Permissions
Use the `-m` flag to set permissions immediately. For example, to create a folder with read, write, and execute for everyone:
mkdir -m 777 public_folder
The number `777` grants full access. You can use any permission set (like `755` for typical directories). This is handy for shared folders or web servers.
Creating Folders With Dates Or Timestamps
Automate folder names with command substitution. For example, create a folder with today’s date:
mkdir backup_$(date +%Y%m%d)
This creates `backup_20250315` (or whatever date it is). You can customize the format—like `%Y-%m-%d` for hyphens. Perfect for logs or backups.
Creating Folders From A File List
If you have a text file with folder names (one per line), use `xargs`:
xargs mkdir < folder_list.txt
This reads each line and creates a folder. Make sure the file has no extra spaces or empty lines. It's great for batch operations.
Creating Folders With Variables
Store a folder name in a variable and use it:
folder_name="my_project"
mkdir $folder_name
This is useful in scripts. You can also combine variables with paths:
base="/home/user"
mkdir $base/data
Always quote variables if they might contain spaces: `mkdir "$base/data"`.
Creating Folders And Moving Into Them
Combine `mkdir` and `cd` in one line using `&&`:
mkdir new_folder && cd new_folder
This creates the folder and immediately moves into it. The `&&` ensures `cd` only runs if `mkdir` succeeds. Handy for quick setups.
Creating Folders With Hidden Names
Folders starting with a dot (`.`) are hidden. Create one like this:
mkdir .hidden_folder
It won't show with a regular `ls`—use `ls -a` to see it. Hidden folders are common for configuration files (e.g., `.config`).
Creating Folders With A Specific Path
You don't have to be in the target directory. Specify the full or relative path:
mkdir /tmp/test_folder
or
mkdir ../parent_folder
The `..` means "parent directory." This lets you create folders anywhere without moving around.
Common Errors And How To Fix Them
- File exists: The folder already exists. Use `-p` to suppress the error or delete it first.
- Permission denied: You don't have write access. Use `sudo` (e.g., `sudo mkdir /root/folder`) or change to a writable location.
- Invalid name: Avoid characters like `/` or null bytes. Stick to letters, numbers, underscores, and hyphens.
- Too many arguments: You forgot quotes around a name with spaces. Wrap it in quotes.
Tips For Efficient Folder Creation
- Use tab completion: Type part of the name and press Tab to auto-complete.
- Create folders in bulk with brace expansion: `mkdir {jan,feb,mar}_reports` creates three folders.
- Combine with other commands: `mkdir data && cp file.txt data/`
- Use `mkdir -v` for verbose output: Shows "created directory 'folder_name'" for each.
- Check your current directory with `pwd` before creating folders to avoid surprises.
Real-World Examples
Setting up a project:
mkdir -p project/{src,docs,tests}
cd project
touch src/main.py docs/readme.md tests/test_main.py
This creates a standard structure with subfolders and files.
Organizing downloads:
mkdir -p ~/Downloads/{images,documents,archives}
mv *.jpg ~/Downloads/images/
Sorts files by type quickly.
Backup script:
backup_dir="backup_$(date +%Y%m%d_%H%M%S)"
mkdir $backup_dir
cp -r important_data $backup_dir/
Creates a timestamped backup folder.
Advanced: Using Mkdir In Scripts
In shell scripts, always check if `mkdir` succeeds:
if mkdir -p /backup/data; then
echo "Folder created"
else
echo "Failed to create folder" >&2
exit 1
fi
This prevents errors from breaking your script. Use `set -e` to exit on any failure.
Frequently Asked Questions
How do I create a folder in Linux terminal with a specific owner?
Use `sudo mkdir folder_name` then `sudo chown user:group folder_name`. Or combine with `install -d -o user -g group folder_name`.
Can I create a folder with a name that starts with a number?
Yes, Linux allows it. For example, `mkdir 2025_data` works fine. No special rules for starting characters.
What's the difference between mkdir and mkdir -p?
`mkdir` creates only the last directory in a path. `mkdir -p` creates all parent directories if they don't exist, and doesn't error if the folder already exists.
How do I create a folder in a different directory without cd?
Specify the full path: `mkdir /home/user/new_folder`. Or use a relative path: `mkdir ../sibling_folder`.
Why does mkdir say "No such file or directory"?
This usually means a parent directory in the path doesn't exist. Use `mkdir -p` to create parent directories automatically.
Summary
Mastering `mkdir` is a fundamental Linux skill. You've learned the basic command, how to create multiple folders, nested directories, handle spaces, set permissions, and use it in scripts. Practice these examples, and you'll create folders efficiently every time.
Remember: `mkdir` is quiet when it works. If you see no output, you succeeded. If you get an error, check your path, permissions, and syntax. With these techniques, you can organize any file system from the terminal.
Now go ahead and create some folders. The terminal is your tool—use it confidently.