Organizing your Linux system begins with understanding how to create folder in linux. This simple yet essential skill helps you keep files tidy, manage projects, and navigate your system efficiently. Whether you are a beginner or brushing up on basics, this guide covers everything from the mkdir command to advanced folder creation techniques.
Linux uses a hierarchical file system, and folders (also called directories) are the building blocks of that structure. Creating them is straightforward once you know the commands. Let’s start with the most common method.
Using The Mkdir Command
The primary command for creating folders in Linux is mkdir, short for “make directory.” Open your terminal and type:
mkdir foldername
This creates a single folder in your current working directory. For example, mkdir projects makes a folder named “projects.” You can verify it with ls.
Creating Multiple Folders At Once
You can create several folders in one command by listing them separated by spaces:
mkdir folder1 folder2 folder3
This is faster than running mkdir multiple times. Each folder is created in the current directory.
Creating Nested Folders With -P
To create a folder inside another folder that doesn’t exist yet, use the -p (parents) flag:
mkdir -p parent/child/grandchild
This creates the entire path at once. Without -p, you’d get an error if “parent” didn’t exist.
How To Create Folder In Linux With Specific Permissions
Sometimes you need a folder with custom permissions. Use the -m (mode) flag:
mkdir -m 755 myfolder
This sets read, write, and execute permissions for the owner, and read+execute for others. You can adjust the number to match your needs.
Checking Folder Creation
After creating a folder, confirm it exists:
- Use
ls -lto see details like permissions and timestamps. - Use
ls -d */to list only directories. - Use
find . -type d -name "foldername"for deeper searches.
Creating Folders In Specific Locations
You don’t have to be in the directory where you want the folder. Provide the full path:
mkdir /home/username/Documents/newfolder
Or use relative paths like mkdir ../backup to create a folder one level up.
Using Variables And Brace Expansion
Brace expansion lets you create multiple folders with patterns:
mkdir {folderA,folderB,folderC}
You can also combine with numbers:
mkdir project{1,2,3}
This creates project1, project2, and project3. It’s a time-saver for bulk creation.
Creating Hidden Folders
Hidden folders in Linux start with a dot (.). Create them like any other folder:
mkdir .hiddenfolder
These won’t appear in ls without the -a flag. Use them for configuration files or private data.
Creating Folders With Spaces In Names
If your folder name has spaces, enclose it in quotes or escape the space:
mkdir "my folder"
Or: mkdir my\ folder. Both work, but quotes are easier to read.
Using The GUI To Create Folders
If you prefer a graphical interface, most Linux desktop environments let you create folders with a right-click. In Nautilus (GNOME), Dolphin (KDE), or Thunar (XFCE), right-click in a folder and select “New Folder” or “Create Folder.”
You can also use the keyboard shortcut Ctrl+Shift+N in many file managers. This is ideal for users who avoid the terminal.
Creating Folders Via Scripts
For automation, use mkdir inside a bash script:
#!/bin/bash
mkdir -p /backup/$(date +%Y-%m-%d)
This creates a dated backup folder daily. Scripts are powerful for repetitive tasks.
Common Errors And Solutions
You might encounter errors when creating folders. Here are frequent issues:
- Permission denied: You don’t have write access to the location. Use
sudo mkdiror change to a writable directory. - File exists: A file or folder with that name already exists. Choose a different name or remove the existing one.
- Invalid name: Avoid special characters like
/or\0in folder names.
Using Mkdir With Other Commands
Combine mkdir with other commands for efficiency:
mkdir newfolder && cd newfolder
This creates the folder and immediately moves into it. The && ensures the second command runs only if the first succeeds.
How To Create Folder In Linux For Multiple Users
When setting up shared folders, consider permissions and ownership:
sudo mkdir /shared
sudo chown :users /shared
sudo chmod 775 /shared
This makes the folder writable by the “users” group. Adjust as needed for your environment.
Creating Temporary Folders
For temporary files, use mktemp:
mktemp -d
This creates a unique temporary folder in /tmp. It’s secure and auto-cleaned on reboot.
Advanced Folder Creation Techniques
For power users, mkdir supports more options:
mkdir -vprints a message for each folder created.mkdir --helpshows all available flags.- Combine with
xargsto create folders from a list:
cat folderlist.txt | xargs mkdir -p
This reads folder names from a file and creates them.
Creating Folders With Timestamps
Use date commands to create time-stamped folders:
mkdir backup_$(date +%Y%m%d_%H%M%S)
This creates folders like “backup_20250315_143022”. Great for logs and backups.
Best Practices For Folder Naming
Follow these tips to avoid issues:
- Use lowercase letters to prevent case-sensitivity problems.
- Replace spaces with underscores or hyphens.
- Avoid starting with a dash, as it can be mistaken for a command option.
- Keep names short but descriptive.
Creating Folders In The Home Directory
Your home directory (~) is the safest place to practice:
mkdir ~/testfolder
This creates a folder in your home. You can also use $HOME instead of ~.
Using Find And Mkdir Together
To create folders based on file patterns, combine commands:
find . -type f -name "*.txt" -exec mkdir -p {}.dir \;
This creates a folder for each text file. Advanced but powerful for organization.
Creating Symbolic Links To Folders
While not a folder creation per se, you can link to folders:
ln -s /original/folder /link/folder
This creates a shortcut. Useful for accessing deep paths quickly.
How To Create Folder In Linux With Specific Owner
Use chown after creation:
sudo mkdir /opt/myapp
sudo chown username:group /opt/myapp
This sets ownership. You can also combine with install command:
sudo install -d -o username -g group /opt/myapp
The install command creates directories with specified ownership in one step.
Creating Folders Across Network Drives
If you have mounted network shares, use mkdir as usual:
mkdir /mnt/network/share/newfolder
Ensure you have write permissions on the remote system.
Using Mkdir In Cron Jobs
Automate folder creation with cron:
0 2 * * * mkdir -p /backup/$(date +\%Y-\%m-\%d)
This runs daily at 2 AM. Escape percent signs in cron syntax.
Creating Folders With Extended Attributes
Linux supports extended attributes for folders:
setfattr -n user.comment -v "important" myfolder
This adds metadata. Not common for basic use, but useful in advanced setups.
Common Mistakes Beginners Make
Avoid these pitfalls:
- Forgetting the
-pflag for nested folders. - Using spaces without quotes.
- Running mkdir without proper permissions.
- Typing
mkidrinstead ofmkdir.
Recovering From Mistakes
If you create a folder in the wrong place, move it with mv:
mv wrongfolder /correct/location/
Or delete it with rmdir (if empty) or rm -r (if not).
How To Create Folder In Linux Using Different Shells
The mkdir command works in bash, zsh, fish, and most shells. Syntax is identical. However, brace expansion might vary in some shells—test first.
Creating Folders With Special Characters
To create folders with symbols like ! or @, use quotes:
mkdir "my@folder!"
Avoid using / or \0 as they are reserved.
Performance Tips For Bulk Folder Creation
Creating thousands of folders? Use loops or parallel:
for i in {1..1000}; do mkdir "folder$i"; done
This creates 1000 folders quickly. For even faster bulk creation, consider using seq with xargs.
Using Mkdir With Sudo
When creating folders in system directories like /usr/local, use sudo:
sudo mkdir /usr/local/myapp
Be cautious—incorrect permissions can break your system.
Creating Folders For Web Development
For web projects, create a standard structure:
mkdir -p myproject/{css,js,images,fonts}
This creates subfolders for assets. Add index.html later.
Using Mkdir With Git Repositories
When cloning a repo, the folder is created automatically. But you can create a parent folder first:
mkdir myrepo && cd myrepo && git clone url
This keeps your projects organized.
How To Create Folder In Linux On Different Distributions
Mkdir works identically on Ubuntu, Fedora, Arch, Debian, and others. The command is part of GNU coreutils, so it’s universal.
Creating Folders In WSL (Windows Subsystem For Linux)
WSL users can use mkdir normally:
mkdir /mnt/c/Users/YourName/linuxfolder
This creates a folder accessible from Windows.
Using Mkdir With Environment Variables
You can use variables in folder names:
USERNAME="john"
mkdir /home/$USERNAME/data
This dynamic creation is useful in scripts.
Creating Folders With Date Ranges
For logs, create monthly folders:
mkdir -p logs/{2025/{01,02,03}}
This creates a nested structure for the first quarter of 2025.
Security Considerations
When creating folders, be mindful of permissions:
- World-writable folders (777) are risky. Use 755 or 750 instead.
- Avoid creating folders in /tmp for sensitive data.
- Use
umaskto set default permissions.
Creating Folders With ACLs
Access Control Lists offer fine-grained permissions:
setfacl -m u:username:rwx myfolder
This gives specific users access without changing group ownership.
How To Create Folder In Linux And Set Sticky Bit
The sticky bit prevents users from deleting each other’s files:
mkdir /shared && chmod +t /shared
Common in /tmp directories.
Creating Folders With Case Sensitivity
Linux is case-sensitive, so “Folder” and “folder” are different. Plan naming carefully to avoid confusion.
Using Mkdir With Output Redirection
You can suppress errors:
mkdir newfolder 2>/dev/null
This hides error messages. Useful in scripts.
Creating Folders With Inodes
Every folder uses an inode. You can check inode count with df -i. If inodes run out, you can’t create more folders.
Conclusion
Mastering how to create folder in linux is a foundational skill that streamlines file management. From basic mkdir commands to advanced techniques like brace expansion and permission setting, you now have the tools to organize any system. Practice in a safe directory, experiment with flags, and soon folder creation will become second nature.
Frequently Asked Questions
How Do I Create A Folder In Linux Using The Terminal?
Use the mkdir command followed by the folder name. For example, mkdir myfolder creates a folder in your current directory.
Can I Create Multiple Folders At Once In Linux?
Yes, list them separated by spaces: mkdir folder1 folder2 folder3. Use brace expansion for patterns: mkdir {a,b,c}.
What Does Mkdir -P Do In Linux?
The -p flag creates parent directories as needed. For example, mkdir -p a/b/c creates all three folders even if “a” doesn’t exist.
How To Create A Hidden Folder In Linux?
Start the folder name with a dot: mkdir .hidden. It won’t show in ls without the -a flag.
What Is The Difference Between Mkdir And Rmdir?
mkdir creates folders, while rmdir removes empty folders. Use rm -r for non-empty folders.