Creating a new folder in Linux is a basic operation that uses the mkdir command, but you can also set permissions right away. If you are new to Linux, learning how to create a new folder in linux is one of the first skills you need. This guide will show you every method, from simple commands to advanced options.
Linux folders are called directories. You create them with the mkdir command. The name stands for “make directory.” It is fast and flexible.
How To Create A New Folder In Linux
Let us start with the simplest way. Open your terminal. Type mkdir foldername and press Enter. Replace “foldername” with your chosen name. The folder appears in your current location.
For example, to create a folder called “projects”:
mkdir projects
That is all. The folder is ready. You can check it with ls command.
Create Multiple Folders At Once
You can create several folders in one command. Just list their names separated by spaces.
mkdir folder1 folder2 folder3
This creates three folders in your current directory. It saves time when you need many folders.
Create Nested Folders
Sometimes you need a folder inside another folder. Use the -p option. This creates parent folders if they do not exist.
mkdir -p parent/child/grandchild
This command creates “parent,” then “child” inside it, then “grandchild” inside that. Without -p, you would get an error if “parent” did not exist.
Create Folder With Spaces In Name
Folder names can have spaces. But you must use quotes or escape the space.
mkdir "my folder"
Or use a backslash:
mkdir my\ folder
Both work. Avoid spaces if possible. They make commands harder to type.
Set Permissions When Creating A Folder
You can set folder permissions right when you create it. Use the -m option followed by permission numbers.
mkdir -m 755 securefolder
This creates a folder with read, write, and execute for the owner, and read and execute for others. Permissions use octal numbers.
- 7 = read (4) + write (2) + execute (1)
- 5 = read (4) + execute (1)
- 0 = no permissions
Common permission sets:
- 755: Owner full access, others read and execute
- 700: Owner only full access
- 777: Everyone full access (not recommended)
Setting permissions at creation is efficient. You avoid extra chmod commands.
Create Folder With Verbose Output
Use -v to see what mkdir does. It prints each folder it creates.
mkdir -v newfolder
Output: mkdir: created directory 'newfolder'
This helps when you create many folders and want confirmation.
Create Folder In A Specific Location
You are not stuck in your current directory. Provide the full path.
mkdir /home/username/Documents/work
Or use relative paths:
mkdir ../backup
This creates a folder named “backup” one level up from your current location.
Using Variables For Folder Names
You can use variables in folder names. This is useful in scripts.
DATE=$(date +%Y-%m-%d)
mkdir backup_$DATE
This creates a folder like “backup_2025-03-20”. Very handy for automated tasks.
Create Folder With Current Date And Time
Combine mkdir with date commands for timestamped folders.
mkdir "$(date +%Y%m%d_%H%M%S)"
This creates a folder named “20250320_143022”. Perfect for logs or backups.
Create Hidden Folders
Hidden folders start with a dot. They do not show with normal ls.
mkdir .config
Use ls -a to see them. Hidden folders are common for application settings.
Create Folder With Specific Ownership
You can set owner and group at creation. Use sudo if needed.
sudo mkdir /opt/myapp
sudo chown user:group /opt/myapp
Or combine with install command for more control.
Create Folder And Set ACL Permissions
Access Control Lists give fine-grained permissions. Create the folder first, then set ACL.
mkdir shared
setfacl -m u:john:rwx shared
This gives user “john” full access to the folder.
Common Errors And Solutions
New users often see errors. Here are common ones.
Permission Denied
You cannot create folders in protected areas like /etc without root.
sudo mkdir /etc/myfolder
Use sudo carefully. Only when needed.
File Exists
If a folder with that name already exists, mkdir shows an error.
mkdir: cannot create directory 'test': File exists
Check with ls first. Or use -p which ignores existing folders.
Invalid Characters
Avoid characters like /, \0, or : in folder names. They cause errors.
Stick to letters, numbers, underscores, and hyphens.
Create Folder In GUI File Manager
Not everyone uses terminal. In most Linux desktops, right-click in a folder and select “New Folder” or “Create Folder.”
In Nautilus (GNOME): Right-click > New Folder. In Dolphin (KDE): Right-click > Create New > Folder. In Thunar (XFCE): Right-click > Create Folder.
GUI methods are fine for occasional use. But terminal is faster for bulk operations.
Create Folder From Script
Scripts automate folder creation. Here is a simple bash script.
#!/bin/bash
for i in {1..5}; do
mkdir "folder_$i"
done
Save as create_folders.sh, make executable with chmod +x create_folders.sh, then run ./create_folders.sh.
This creates five folders: folder_1 through folder_5.
Create Folder With Template Files
You can create a folder and copy template files in one step.
mkdir newproject && cp -r /templates/project/* newproject/
This creates “newproject” and copies all files from the template directory into it.
Create Folder And Change Into It
Use && to chain commands.
mkdir myfolder && cd myfolder
This creates the folder and moves into it. Saves a step.
Create Folder With Error Handling
In scripts, check if folder exists before creating.
if [ ! -d "myfolder" ]; then
mkdir myfolder
fi
This prevents errors and unwanted overwrites.
Create Folder Using Mkdir With Dry Run
There is no built-in dry run for mkdir. But you can simulate with echo.
echo mkdir testfolder
This shows what would run. Remove echo to execute.
Create Folder In Different File Systems
Linux supports many file systems. mkdir works on ext4, NTFS, FAT32, and others. But permissions may behave differently on non-native systems.
On FAT32, you cannot set Linux permissions. On NTFS, permissions are managed by the mount options.
Create Folder On USB Drive
Mount the USB first. Then create folders normally.
sudo mount /dev/sdb1 /mnt/usb
mkdir /mnt/usb/myfolder
Unmount safely when done: sudo umount /mnt/usb.
Create Folder With Special Permissions
Setuid, setgid, and sticky bit are special permissions.
- Setuid (4000): Runs with owner’s privileges
- Setgid (2000): New files inherit group
- Sticky bit (1000): Only owner can delete files
Set them with mkdir and -m:
mkdir -m 2755 sharedgroup
This sets setgid (2) with permissions 755. New files in this folder will belong to the folder’s group.
Create Folder With Extended Attributes
Extended attributes store metadata. Use setfattr after creation.
mkdir myfolder
setfattr -n user.note -v "important" myfolder
This adds a custom attribute. View with getfattr -d myfolder.
Create Folder In A Chroot Environment
In a chroot, you work inside a restricted directory tree. mkdir works normally inside it.
sudo chroot /mnt/chroot
mkdir /newfolder
This creates a folder inside the chroot environment.
Create Folder Using Find With Mkdir
Combine find and mkdir to create folders based on file patterns.
find . -name "*.txt" -exec mkdir -p {}.folder \;
This creates a folder for each .txt file. Advanced but powerful.
Create Folder With Date In Name From File
Read a list of names from a file and create folders.
while read line; do mkdir "$line"; done < names.txt
Each line in names.txt becomes a folder name.
Create Folder And Set SELinux Context
On systems with SELinux, you may need to set context.
mkdir /var/www/html/myapp
semanage fcontext -a -t httpd_sys_content_t "/var/www/html/myapp(/.*)?"
restorecon -Rv /var/www/html/myapp
This ensures the web server can access the folder.
Create Folder With Encryption
For encrypted folders, use eCryptfs or LUKS. mkdir works on the encrypted mount point.
mkdir ~/Private
ecryptfs-setup-private
This sets up an encrypted private folder.
Create Folder In RAM Disk
RAM disks are fast but temporary. Mount a tmpfs and create folders.
sudo mount -t tmpfs -o size=1G tmpfs /mnt/ram
mkdir /mnt/ram/work
Data is lost on reboot.
Create Folder With Compression
Linux does not compress folders directly. Use tar or zip after creation.
mkdir myfolder
tar -czf myfolder.tar.gz myfolder
This creates a compressed archive of the folder.
Create Folder And Sync To Cloud
After creating a folder, sync it with rclone or rsync.
mkdir cloudbackup
rclone sync cloudbackup remote:backup
This syncs the local folder to a cloud storage.
Create Folder With Monitoring
Use inotifywait to watch for new folders.
inotifywait -m /path -e create | while read; do echo "New folder created"; done
This monitors a directory and alerts when a new folder appears.
Create Folder And Add To Git
Git does not track empty folders. Add a .gitkeep file.
mkdir myproject
touch myproject/.gitkeep
git add myproject/.gitkeep
This keeps the folder in the repository.
Create Folder With Version Control
Use mkdir with a version number.
mkdir project_v1.0
mkdir project_v1.1
Simple but effective for manual versioning.
Create Folder And Set Quota
On systems with quotas, you can limit folder size.
mkdir /home/user/quota_test
setquota -u user 100M 120M 0 0 /home
This limits the user's disk usage.
Create Folder With Notification
Send an alert after creating a folder.
mkdir newfolder && notify-send "Folder created" "newfolder is ready"
This shows a desktop notification.
Create Folder And Log It
Log folder creation for auditing.
mkdir newfolder && echo "$(date): Created newfolder" >> /var/log/folder_creation.log
This appends a log entry.
Create Folder In A Loop
Create numbered folders quickly.
for i in {1..100}; do mkdir "folder_$i"; done
This creates 100 folders in seconds.
Create Folder With Random Name
Use mktemp for random names.
mktemp -d /tmp/temp.XXXXXX
This creates a temporary folder with a random name.
Create Folder And Set Immutable Attribute
Make a folder read-only even for root.
mkdir protected
sudo chattr +i protected
Now the folder cannot be modified or deleted until you remove the attribute with chattr -i.
Create Folder With ACL For Multiple Users
Give access to several users.
mkdir teamproject
setfacl -m u:alice:rwx,u:bob:rwx teamproject
Alice and Bob have full access.
Create Folder And Set Default ACL
New files inherit default permissions.
mkdir shared
setfacl -d -m u:alice:rwx shared
Any new file in "shared" will give Alice read, write, and execute.
Create Folder With Case Sensitivity
Linux is case-sensitive. "Folder" and "folder" are different.
mkdir Folder
mkdir folder
Both exist. Be careful with case.
Create Folder On Remote Server
Use SSH to create folders remotely.
ssh user@server "mkdir /home/user/remote_folder"
This creates a folder on the remote machine.
Create Folder With Rsync
Rsync can create folders if they do not exist.
rsync -av --mkpath /local/folder/ user@server:/remote/folder/
This creates the remote folder if missing.
Create Folder And Set Backup Flag
Use extended attributes to mark for backup.