Creating a new folder in Linux uses the mkdir command followed by your chosen folder name. If you are new to Linux and wondering how to make folder in linux, you have come to the right place. This guide will walk you through every step, from the simplest command to advanced options, so you can manage your files like a pro.
Linux is a powerful operating system used by developers, sysadmins, and everyday users. One of the first things you learn is how to organize your files by creating folders. Whether you are using a terminal or a graphical interface, the process is straightforward once you know the basics.
In this article, we will cover everything you need to know about creating folders in Linux. You will learn the mkdir command, how to create nested directories, set permissions, and avoid common mistakes. By the end, you will be able to create folders with confidence.
How To Make Folder In Linux
The most common way to create a folder in Linux is by using the mkdir command. The name stands for “make directory.” It is simple to use and works on almost every Linux distribution.
Open your terminal. You can usually find it in your applications menu or press Ctrl + Alt + T. Once the terminal is open, type the following command and press Enter:
mkdir myfolder
This will create a folder named “myfolder” in your current directory. You can check if it was created by typing ls and looking for the folder name in the list.
If you want to create a folder with a space in its name, you need to use quotes or escape the space. For example:
mkdir "my folder"
Or:
mkdir my\ folder
Both methods work, but using quotes is easier for beginners.
Creating Multiple Folders At Once
You can create several folders in one command by listing their names separated by spaces. For instance:
mkdir folder1 folder2 folder3
This will create three folders in your current directory. It saves time when you need to set up a project structure quickly.
You can also create folders with a common prefix using curly braces. For example:
mkdir project_{a,b,c}
This creates folders named “project_a”, “project_b”, and “project_c”. It is a handy trick for batch creation.
Creating Nested Folders With -P
Sometimes you need to create a folder inside another folder that does not exist yet. The -p flag allows you to create parent directories automatically. For example:
mkdir -p parent/child/grandchild
This command creates the “parent” folder, then “child” inside it, and finally “grandchild” inside “child”. Without the -p flag, you would get an error if any parent folder was missing.
This is extremly useful when setting up deep directory structures for projects or backups. You can create an entire tree with one command.
Setting Permissions When Creating A Folder
By default, folders are created with standard permissions based on your umask. But you can set specific permissions using the -m flag. For example:
mkdir -m 755 myfolder
This creates a folder with read, write, and execute permissions for the owner, and read and execute for others. You can use any valid permission number.
If you want to create a folder that only you can access, use:
mkdir -m 700 private_folder
This ensures that no one else can read or enter the folder. It is great for sensitive data.
Creating Folders With Specific Dates Or Names
You can combine mkdir with other commands to create folders with dynamic names. For example, to create a folder with today’s date:
mkdir backup_$(date +%Y%m%d)
This creates a folder like “backup_20231005”. It is perfect for automated backup scripts.
You can also use variables. For instance:
name="myproject"
mkdir $name
This gives you flexibility when scripting.
Using The Graphical Interface To Create Folders
If you prefer not to use the terminal, you can create folders using your file manager. Most Linux desktop environments like GNOME, KDE, or XFCE have a simple way to do this.
Open your file manager. Navigate to the location where you want the folder. Right-click on an empty space and select “New Folder” or “Create Folder.” A new folder will appear, and you can rename it immediately.
You can also use the keyboard shortcut Ctrl + Shift + N in many file managers. This is faster than using the mouse.
The graphical method is intuitive and does not require any commands. However, it is less powerful for batch operations or scripting.
Creating Folders In Remote Servers Via SSH
When you work on a remote server, you use SSH to connect. The mkdir command works exactly the same way. For example:
ssh user@server
mkdir /home/user/newfolder
You can also create folders directly without logging in:
ssh user@server "mkdir /home/user/remotefolder"
This is efficient for automation.
Common Mistakes And How To Avoid Them
Even experienced users make mistakes when creating folders. Here are some common ones and how to fix them.
- Typo in folder name: Always double-check your spelling. You can use the
Tabkey for autocompletion to avoid typos. - Missing parent directories: Use the
-pflag to create nested folders automatically. - Permission denied: If you get a “Permission denied” error, you need to use
sudofor system directories. For example:sudo mkdir /root/newfolder. - Folder already exists: The mkdir command will give an error if the folder already exists. Use
-pto suppress this error if needed. - Using spaces without quotes: Always quote folder names with spaces or escape them.
Checking If A Folder Was Created
After creating a folder, you can verify it using the ls command. To see detailed information, use ls -l. This shows permissions, owner, size, and date.
You can also use the file command to confirm it is a directory:
file myfolder
It will output something like “myfolder: directory.”
Deleting Folders You Created By Mistake
If you create a folder by accident, you can remove it with the rmdir command if it is empty. For example:
rmdir myfolder
If the folder has files inside, use rm -r to remove it recursively. Be careful with this command because it deletes everything without confirmation.
rm -r myfolder
Always double-check before deleting.
Advanced Folder Creation Techniques
Once you master the basics, you can use more advanced methods to create folders efficiently.
Using Find To Create Folders Based On File Types
You can combine find with mkdir to create folders for different file types. For example, to create a folder for each file extension in a directory:
for ext in $(find . -maxdepth 1 -type f | sed 's/.*\.//' | sort -u); do mkdir "$ext"; done
This is a bit complex but very powerful for organizing files.
Creating Folders With A Script
You can write a simple bash script to create multiple folders. For instance:
#!/bin/bash
for i in {1..10}; do
mkdir "folder_$i"
done
Save this as a file, make it executable with chmod +x script.sh, and run it. It creates ten folders named folder_1 to folder_10.
Scripts are great for repetitive tasks.
Using Mkdir With Other Commands
You can pipe output from other commands to mkdir. For example, to create folders from a list in a text file:
xargs mkdir < folderlist.txt
Each line in the file becomes a folder name. This is useful for bulk creation.
Permissions And Ownership Explained
When you create a folder, Linux assigns permissions based on your umask. The default umask is usually 022, which gives you read, write, and execute permissions, and others read and execute.
You can change the umask temporarily before creating folders:
umask 077
mkdir secret
This creates a folder with permissions 700, meaning only you can access it.
To change ownership after creation, use the chown command:
sudo chown user:group myfolder
This is important for multi-user systems.
Understanding Folder Permissions
Permissions are represented by three digits: owner, group, and others. Each digit is the sum of read (4), write (2), and execute (1). For folders, execute permission means you can enter the folder.
Common permission sets:
- 755: Owner can read, write, execute; others can read and execute.
- 700: Only owner can access.
- 777: Everyone can do anything (not recommended).
Use chmod to change permissions after creation.
Troubleshooting Common Issues
Sometimes things go wrong. Here are solutions to frequent problems.
Error: "Cannot Create Directory: File Exists"
This happens when the folder already exists. Use -p to suppress the error, or check with ls first.
Error: "Permission Denied"
You do not have write permission in the current directory. Use sudo or change to a directory you own, like your home folder.
Error: "No Such File Or Directory"
This usually means a parent directory in the path does not exist. Use -p to create it automatically.
Folder Name With Special Characters
Some characters like / or \0 are not allowed. Stick to letters, numbers, underscores, and hyphens for safety.
Best Practices For Folder Organization
Good folder names make your life easier. Use descriptive names without spaces if possible. For example, use "project_backup" instead of "project backup."
Use lowercase letters to avoid confusion on case-sensitive systems. Linux treats "Folder" and "folder" as different names.
Plan your folder structure before creating it. A well-organized hierarchy saves time later.
Automating Folder Creation With Cron
You can schedule folder creation using cron jobs. For example, to create a daily backup folder:
0 2 * * * mkdir -p /backups/$(date +\%Y\%m\%d)
This runs every day at 2 AM.
Frequently Asked Questions
What Is The Command To Create A Folder In Linux?
The command is mkdir followed by the folder name. For example: mkdir newfolder.
How Do I Create A Folder With Spaces In The Name?
Use quotes around the name, like mkdir "my folder", or escape the space with a backslash: mkdir my\ folder.
Can I Create Multiple Folders At Once In Linux?
Yes, list the folder names separated by spaces: mkdir folder1 folder2 folder3.
How Do I Create A Folder In A Different Directory?
Provide the full path, for example: mkdir /home/user/Documents/newfolder.
What Does The -P Flag Do In Mkdir?
The -p flag creates parent directories as needed and does not give an error if the folder already exists.
Now you know how to make folder in linux using both the terminal and graphical interface. Practice these commands to become comfortable with file management. With time, you will be able to create complex directory structures quickly and avoid common pitfalls.
Remember to check permissions and use the -p flag for nested folders. If you ever get stuck, the man mkdir command shows the full manual. Happy organizing!