Organizing your system begins with knowing how to create a folder in Linux to keep your files structured. Whether you’re a new user or a seasoned admin, this fundamental skill helps you manage data efficiently.
Folders, also called directories, are the backbone of any Linux file system. Without them, your hard drive would be a chaotic mess of files. In this guide, you’ll learn multiple ways to create folders using commands and graphical tools.
We’ll cover everything from basic mkdir usage to advanced tricks. By the end, you’ll be able to create single folders, nested directories, and folders with permissions set automatically.
Why Knowing How To Create A Folder In Linux Matters
Linux is a command-line powerhouse. But even with graphical desktops, knowing the terminal gives you speed and control. Creating folders is the first step in organizing projects, backups, or server configurations.
Imagine you’re setting up a web server. You need folders for logs, HTML files, and configurations. Without proper folder creation, your setup becomes messy and hard to maintain.
Also, many scripts and automation tasks require folder creation. If you can’t do it from the command line, you’re limited to manual GUI work.
Basic Syntax For Creating Folders
The main command is mkdir, short for “make directory.” The basic syntax is simple:
mkdir folder_name
Replace folder_name with whatever you want. For example:
mkdir projects
This creates a folder named “projects” in your current directory. To see it, use ls or ls -l for details.
If the folder already exists, you’ll get an error: mkdir: cannot create directory ‘projects’: File exists. To avoid this, use the -p flag.
Creating Multiple Folders At Once
You can create several folders in one command by listing their names separated by spaces:
mkdir folder1 folder2 folder3
This creates three folders in your current directory. It’s a huge time saver when setting up project structures.
For example, if you’re starting a new coding project, you might want folders for src, docs, and tests. Just run:
mkdir src docs tests
How To Create A Folder In Linux With Parent Directories
Sometimes you need to create a nested folder structure like project/src/css. Normally, you’d create each folder one by one. But the -p flag does it all at once.
mkdir -p project/src/css
This creates project, then src inside it, then css inside that. No errors if parent folders already exist.
This is perfect for deep directory trees. For instance, when setting up a website, you might run:
mkdir -p /var/www/html/blog/images
The -p flag also suppresses errors if the folder already exists. So it’s safe to use in scripts.
Creating Folders With Specific Permissions
By default, new folders have permissions based on your umask. But you can set permissions directly with the -m flag.
mkdir -m 755 secure_folder
This creates a folder with read, write, and execute for the owner, and read and execute for others. The permissions are set immediately, no need for a separate chmod command.
Common permission values include:
- 755 – Owner can read/write/execute; others can read/execute
- 700 – Only owner has full access
- 777 – Everyone has full access (not recommended for security)
Combine -m with -p for nested folders with specific permissions:
mkdir -m 700 -p private/docs
This creates private and docs with 700 permissions on both.
How To Create A Folder In Linux Using Absolute Paths
You can create folders anywhere on the system by using absolute paths. An absolute path starts from the root directory (/).
mkdir /home/username/new_folder
This creates new_folder in your home directory. You need write permissions to the parent directory. For system folders like /etc, you’ll need sudo.
sudo mkdir /opt/my_app
Using absolute paths is useful when you’re in a different directory but want to create a folder elsewhere. It avoids changing directories.
Creating Folders With Spaces In Names
Linux folder names can have spaces, but you need to handle them carefully. Use quotes or escape the space with a backslash.
mkdir "My Documents"
Or:
mkdir My\ Documents
Both create a folder named “My Documents”. Without quotes or escaping, mkdir would try to create two folders: My and Documents.
It’s generally better to avoid spaces in folder names for scripting. Use underscores or hyphens instead: my_documents or my-documents.
How To Create A Folder In Linux Using GUI
Not everyone lives in the terminal. Most Linux desktops like GNOME, KDE, or Xfce have file managers. Here’s how to create a folder graphically:
- Open your file manager (Nautilus, Dolphin, Thunar, etc.)
- Navigate to where you want the folder
- Right-click in an empty area
- Select “New Folder” or “Create Folder”
- Type the folder name and press Enter
You can also use the keyboard shortcut Ctrl+Shift+N in most file managers. This is faster than right-clicking.
The GUI method is great for beginners or when you’re visually organizing files. But for bulk operations or scripting, the command line is better.
Creating Folders With Special Characters
Linux allows almost any character in folder names except the forward slash (/), which is the directory separator. But special characters like !, @, #, or $ can cause issues in scripts.
To create a folder with special characters, always use quotes:
mkdir "folder#1"
Or escape each character:
mkdir folder\#1
Be careful with $ because it’s used for variables. If you want a folder named $money, use single quotes to prevent variable expansion:
mkdir '$money'
Single quotes treat everything literally. Double quotes still allow some expansions.
How To Create A Folder In Linux With Timestamp Names
Sometimes you need folders named with the current date or time. This is common for backups or logs. Use command substitution with date.
mkdir backup_$(date +%Y%m%d)
This creates a folder like backup_20250315. The $(...) runs the date command and inserts its output.
You can customize the format:
%Y– Year (2025)%m– Month (03)%d– Day (15)%H%M%S– Hour, minute, second
Example for a timestamp with time:
mkdir log_$(date +%Y%m%d_%H%M%S)
This creates log_20250315_143022. Perfect for unique folder names.
Creating Folders From A File List
If you have a list of folder names in a text file, you can create them all at once. Use xargs or a while loop.
Suppose you have folders.txt with one name per line:
src
docs
tests
assets
Run:
xargs mkdir -p < folders.txt
This reads each line and creates the folder. The -p flag ensures parent directories are created if needed.
Alternatively, use a loop:
while IFS= read -r folder; do mkdir "$folder"; done < folders.txt
This is more flexible if you need to add logic, like skipping empty lines.
How To Create A Folder In Linux With Verbose Output
Sometimes you want to see what's happening. The -v flag makes mkdir print each folder it creates.
mkdir -v project/src
Output:
mkdir: created directory 'project'
mkdir: created directory 'project/src'
This is helpful in scripts to confirm actions. Combine with -p for nested folders:
mkdir -vp a/b/c
You'll see each directory being created. It's also good for debugging when things go wrong.
Common Mistakes And How To Avoid Them
New users often make these errors when creating folders:
- Forgetting quotes for spaces – Results in multiple folders or errors
- Using
mkdirwithout-pfor nested paths – Fails if parent doesn't exist - Typo in folder name – Creates a folder you didn't intend
- No permissions – Need
sudofor system directories - Using reserved names – Avoid names like
.or..
Always double-check your path. Use pwd to see your current directory before running mkdir.
How To Create A Folder In Linux For Scripting
In bash scripts, you often need to create folders conditionally. Use mkdir -p because it doesn't error if the folder exists.
#!/bin/bash
BACKUP_DIR="/home/user/backups/$(date +%Y%m%d)"
mkdir -p "$BACKUP_DIR"
# Now copy files into $BACKUP_DIR
This ensures the backup folder exists before copying. The -p flag makes it idempotent – running the script multiple times won't cause errors.
You can also check if a folder exists before creating:
if [ ! -d "new_folder" ]; then
mkdir new_folder
fi
But mkdir -p is simpler for most cases.
Creating Folders With SSH On Remote Servers
Managing remote Linux servers often requires creating folders via SSH. Use the same mkdir command over SSH.
ssh user@server "mkdir -p /var/www/html/new_site"
This creates the folder on the remote server. You can combine multiple commands:
ssh user@server "mkdir -p /var/www/html/new_site && chmod 755 /var/www/html/new_site"
For automation, use SSH keys to avoid password prompts. This is standard for server administration.
How To Create A Folder In Linux With Different File Systems
Linux supports many file systems like ext4, NTFS, FAT32, and Btrfs. The mkdir command works the same on all of them, but there are nuances.
On FAT32, folder names are limited to 8.3 characters in some cases, but modern Linux handles long names fine. NTFS may have case sensitivity issues if mounted with certain options.
For network file systems like NFS or Samba, permissions depend on the server settings. You might need to use sudo or mount with specific options.
Always check the mount options if you get permission errors. Use mount | grep /mountpoint to see current settings.
Creating Temporary Folders
For temporary files, use mktemp instead of mkdir. It creates a unique folder in /tmp and prints its path.
temp_dir=$(mktemp -d)
echo $temp_dir
This creates something like /tmp/tmp.XXXXXX. The folder is automatically deleted on reboot, but you should clean it up in your script.
Use trap to remove it on exit:
temp_dir=$(mktemp -d)
trap "rm -rf $temp_dir" EXIT
This ensures the temporary folder is deleted even if the script crashes.
How To Create A Folder In Linux With Symbolic Links
Sometimes you want a folder that points to another location. That's a symbolic link, not a regular folder. Use ln -s.
ln -s /path/to/target link_name
This creates a symbolic link named link_name that points to /path/to/target. It looks like a folder but is just a pointer.
Symbolic links are useful for organizing without duplicating data. For example, you can link a shared folder into multiple project directories.
To create a symbolic link to a folder, the target must exist. The link name can be anything.
Creating Folders With ACL Permissions
For advanced permission control, use Access Control Lists (ACLs). First create the folder, then set ACLs with setfacl.
mkdir shared_folder
setfacl -m u:john:rwx shared_folder
This gives user john read, write, and execute permissions on shared_folder. ACLs are more granular than standard Unix permissions.
You can also set default ACLs for new files inside the folder:
setfacl -d -m u:john:rwx shared_folder
This ensures any new file or folder created inside shared_folder inherits the ACL for john.
How To Create A Folder In Linux With Encryption
For sensitive data, you might want encrypted folders. Tools like eCryptfs or LUKS can encrypt entire directories.
With eCryptfs, you create a folder and then mount an encrypted version over it:
mkdir ~/Private
ecryptfs-setup-private
This sets up an encrypted folder in your home directory. You'll need to enter a passphrase to access it.
For full-disk encryption, use LUKS during installation. But for per-folder encryption, eCryptfs is simpler.
Remember that encrypted folders require mounting before use. Unmount them when not needed to protect data.
Creating Folders In Docker Containers
When working with Docker, you create folders inside containers just like on a regular Linux system. Use docker exec to run commands.
docker exec container_name mkdir -p /app/data
Or in a Dockerfile:
RUN mk