Creating a new folder in Linux is as simple as typing mkdir followed by your chosen name. If you are wondering how to make a new folder in linux, you have come to the right place. This guide will show you every method, from the basic command to advanced options. You will learn to create folders in your home directory, in specific locations, and even multiple folders at once. Let’s get started.
How To Make A New Folder In Linux
The core command for creating folders in Linux is mkdir. This stands for “make directory.” You use it in the terminal. Open your terminal emulator. Type mkdir, then a space, then the name of your new folder. Press Enter. That is it. Your folder appears in the current directory.
For example, to create a folder named “projects,” you type:
mkdir projects
This works in almost every Linux distribution. Ubuntu, Fedora, Debian, Arch, and others all use the same command. The terminal is your friend. Do not be afraid of it.
Basic Syntax Of The Mkdir Command
The full syntax is:
mkdir [options] directory_name
Here, [options] are optional flags. directory_name is what you want to call your folder. You can add multiple names separated by spaces. This creates several folders at once.
Common options include:
-p– Create parent directories if they do not exist.-v– Show a message for each folder created (verbose).-m– Set permissions on the new folder.
Creating A Single Folder
To make one folder, just type mkdir and the name. For instance:
mkdir my_new_folder
This creates a folder named “my_new_folder” in your current location. If you are in your home directory, it appears there. You can check with the ls command.
Folder names can include letters, numbers, underscores, and hyphens. Avoid spaces in names. If you must use a space, put the name in quotes or escape the space with a backslash. For example:
mkdir "my folder"
Or:
mkdir my\ folder
But it is easier to avoid spaces. Use underscores or hyphens instead.
Creating Multiple Folders At Once
You can create several folders with one command. Just list their names separated by spaces:
mkdir folder1 folder2 folder3
This creates three folders in the current directory. It saves time. You can mix names with and without spaces. Just be careful with quoting.
You can also create folders in different locations. Use full paths:
mkdir /home/user/docs /home/user/photos
This creates two folders in the specified paths. Make sure the parent directories exist. Otherwise, you get an error.
Creating Nested Folders With The -P Option
Sometimes you need to create a folder inside another folder that does not exist yet. For example, you want projects/2025/reports. If projects and 2025 do not exist, a normal mkdir fails. Use the -p option:
mkdir -p projects/2025/reports
This creates all three folders. It creates projects, then 2025 inside it, then reports inside that. The -p flag is very useful. It prevents errors when parent directories are missing.
You can also use -p to create multiple nested structures:
mkdir -p a/b/c d/e/f
This creates two separate nested paths. Each path is created fully.
Creating A Folder With Specific Permissions
By default, new folders have permissions based on your umask. But you can set permissions directly with the -m option. For example, to create a folder with read, write, and execute for everyone:
mkdir -m 777 public_folder
This sets permissions to 777. That means everyone can read, write, and execute. Be careful with this. It is often too open. Use 755 for normal folders. That gives full access to you, and read/execute to others.
mkdir -m 755 my_folder
You can also use symbolic permissions:
mkdir -m u=rwx,g=rx,o=rx my_folder
This does the same as 755. The -m option is powerful. Use it when you need specific access controls.
Creating A Folder In A Specific Directory
You do not have to be in the target directory. Use a full path or a relative path. For example, to create a folder in your home directory from anywhere:
mkdir ~/new_folder
The tilde ~ represents your home directory. You can also use absolute paths:
mkdir /tmp/test_folder
Relative paths work too. If you are in /home/user, you can create a folder in docs like this:
mkdir docs/new_folder
This assumes docs already exists. If not, use -p.
Using Mkdir With Variables
You can use shell variables to create folders dynamically. For example:
DATE=$(date +%Y-%m-%d)
mkdir backup_$DATE
This creates a folder named like “backup_2025-03-15”. The variable $DATE holds the current date. You can use any variable. This is great for scripts.
You can also use command substitution:
mkdir $(whoami)_files
This creates a folder with your username. Very handy for automated tasks.
Creating A Folder With A Specific Parent Directory
Sometimes you want to create a folder inside a directory that may or may not exist. Use -p to avoid errors. For example:
mkdir -p /var/log/myapp/2025
This creates /var/log/myapp if it does not exist, then creates 2025 inside it. The -p option is forgiving. It does not complain if the parent already exists.
You can also combine -p with -v to see what was created:
mkdir -pv /tmp/a/b/c
This shows each folder as it is created. Very useful for debugging.
Creating A Folder With A Trailing Slash
You can add a trailing slash to the folder name. It does not change anything. Both commands work the same:
mkdir myfolder/
mkdir myfolder
The slash is optional. Some people use it to emphasize it is a directory. But it is not required.
Creating A Folder With A Dot Prefix (Hidden Folder)
In Linux, folders starting with a dot are hidden. They do not show up with a normal ls command. To create a hidden folder, just start the name with a dot:
mkdir .hidden_folder
This creates a hidden folder. You can see it with ls -a. Hidden folders are often used for configuration files. For example, .config or .ssh.
You can create hidden nested folders too:
mkdir -p .config/myapp
This creates a hidden .config folder and a myapp folder inside it.
Common Errors And How To Fix Them
When using mkdir, you might see errors. Here are common ones:
- File exists: The folder already exists. Use a different name or delete the old one.
- Permission denied: You do not have write access to the parent directory. Use
sudoor change to a writable location. - No such file or directory: The parent directory does not exist. Use
-pto create it. - Invalid argument: The folder name contains illegal characters. Avoid slashes, null bytes, or other special characters.
To avoid these, always check your current directory with pwd. Make sure you have the right permissions. Use -p for nested folders.
Creating Folders With Special Characters In Names
If you need a folder name with spaces, quotes, or other special characters, escape them. Use backslashes:
mkdir my\ folder\ name
Or use quotes:
mkdir "my folder name"
Single quotes work too:
mkdir 'my folder name'
Be consistent. Avoid special characters if possible. They make scripting harder.
Creating Folders Using A Loop
In scripts, you might want to create many folders with patterns. Use a for loop:
for i in {1..10}; do mkdir "folder_$i"; done
This creates folder_1 through folder_10. You can change the range. You can also use letters:
for letter in {a..e}; do mkdir "dir_$letter"; done
This creates dir_a through dir_e. Loops are powerful for bulk operations.
Creating Folders With Timestamps
You can include timestamps in folder names. This is useful for backups. Use the date command:
mkdir backup_$(date +%Y%m%d_%H%M%S)
This creates a folder like “backup_20250315_143022”. The timestamp is precise. You can customize the format. Use date --help to see options.
Creating A Folder And Changing Into It
Sometimes you want to create a folder and immediately move into it. You can combine commands:
mkdir new_folder && cd new_folder
The && runs the second command only if the first succeeds. This is a common pattern. You can also use a function in your shell:
mkcd() { mkdir -p "$1" && cd "$1"; }
Then just type mkcd new_folder. This creates and enters the folder in one step.
Using Mkdir With Sudo
If you need to create a folder in a system directory, you need root privileges. Use sudo:
sudo mkdir /opt/myapp
You will be prompted for your password. Be careful. Only use sudo when necessary. Creating folders in your home directory does not need it.
Creating A Folder With A Specific Owner
After creating a folder, you can change its owner with chown. But you can also create it with a specific owner if you have root:
sudo mkdir /tmp/test && sudo chown user:group /tmp/test
Or use install command for more control. But mkdir does not have an owner option. So you do it in two steps.
Creating A Folder With A Specific Group
Similar to owner, set the group after creation:
mkdir myfolder
chgrp mygroup myfolder
Or use chown with group:
chown :mygroup myfolder
This sets the group without changing the owner.
Creating A Folder And Setting ACL
For advanced permissions, use ACL (Access Control Lists). First create the folder, then set ACL:
mkdir shared_folder
setfacl -m u:john:rwx shared_folder
This gives user John full access. ACL is more flexible than standard permissions.
Creating A Folder In A Read-Only Filesystem
If you try to create a folder on a read-only filesystem, you get an error. Check with mount or df -h. Remount with write access if needed:
sudo mount -o remount,rw /mountpoint
Then try again. Be careful with system partitions.
Creating A Folder With A Symlink
You can create a symbolic link to a folder. But that is not mkdir. Use ln -s:
ln -s /path/to/original link_name
This creates a link, not a new folder. Links point to existing folders.
Creating A Folder In A Script
In bash scripts, use mkdir with checks. For example:
#!/bin/bash
if [ ! -d "$1" ]; then
mkdir -p "$1"
echo "Created $1"
else
echo "Folder $1 already exists"
fi
This script creates a folder if it does not exist. It uses -d to check. This is robust.
Creating A Folder With A Specific Date In Name
You can use date to create folders with dates. For example, for daily logs:
mkdir logs_$(date +%Y-%m-%d)
This creates a folder like “logs_2025-03-15”. You can automate this in cron jobs.
Creating A Folder With A Random Name
Use mktemp for temporary folders. But for random names, you can use uuidgen:
mkdir $(uuidgen)
This creates a folder with a UUID. Very unique. Or use date with nanoseconds:
mkdir temp_$(date +%N)
This uses nanoseconds. But it is not truly random.
Creating A Folder With A Specific Size
Folders do not have size. They are just containers. But you can create a folder and then fill it with files of a specific size. That is beyond mkdir.
Creating A Folder And Making It Immutable
After creation, you can make a folder immutable with chattr:
mkdir secure_folder
sudo chattr +i secure_folder
This prevents any changes, even by root. Use with caution.
Creating A Folder With A Specific Inode Number
You cannot set inode numbers. They are assigned by the filesystem. So this is not possible with mkdir.
Creating A Folder On A Different Filesystem
You can create folders on any mounted filesystem. Just specify the path:
mkdir /mnt/usb/myfolder
Make sure the filesystem is writable. Some filesystems like NTFS may have restrictions.
Creating A Folder With A Specific Encoding
Folder names are just bytes. But if you use UTF-8 characters, ensure your terminal supports it. Most modern systems do. For example:
mkdir 文件夹