How To Make A Folder In Linux – Mkdir Command With Parent Directories

Organizing your data starts with knowing how to create a folder in Linux using the mkdir command. If you’re new to Linux, understanding how to make a folder in linux is one of the first steps to managing your files effectively. Whether you’re using Ubuntu, Fedora, or any other distribution, the process is straightforward and consistent across most systems.

In this guide, you’ll learn multiple ways to create folders, from basic commands to advanced techniques. We’ll cover everything you need to become confident with directory creation in Linux.

How To Make A Folder In Linux

The most common way to create a folder in Linux is with the mkdir command. This command stands for “make directory” and is available on every Linux system. Let’s start with the basics.

Using The Mkdir Command

Open your terminal. Type mkdir followed by the folder name you want to create. For example:

mkdir myfolder

This creates a folder named “myfolder” in your current directory. The command is case-sensitive, so “MyFolder” and “myfolder” are different.

You can verify the folder was created by typing ls to list directory contents. You should see your new folder in the list.

Creating Multiple Folders At Once

Need to create several folders quickly? You can pass multiple names to mkdir:

mkdir folder1 folder2 folder3

This creates three separate folders in one command. It’s a huge time saver when organizing projects.

Creating Nested Folders

Sometimes you need to create a folder inside another folder that doesn’t exist yet. Use the -p flag:

mkdir -p projects/2024/reports

The -p flag tells mkdir to create parent directories as needed. If “projects” and “2024” don’t exist, they’ll be created automatically.

This is extremely useful for setting up complex directory structures in one go.

Creating Folders With Spaces In Names

Folder names with spaces require special handling. Use quotation marks or escape the spaces:

mkdir "My Documents"

Or with backslash escaping:

mkdir My\ Documents

Both methods work, but quotation marks are generally easier to read and type.

Creating Folders With Specific Permissions

By default, folders are created with standard permissions. You can set specific permissions using the -m flag:

mkdir -m 755 securefolder

This creates a folder with read, write, and execute permissions for the owner, and read and execute for everyone else.

Common permission values include:

  • 755 – Owner can read/write/execute; others can read/execute
  • 700 – Only owner can access
  • 777 – Everyone can read/write/execute (use cautiously)

Using Absolute And Relative Paths

You can create folders anywhere on your system using paths. Relative paths start from your current location:

mkdir ../siblingfolder

This creates a folder in the parent directory. Absolute paths start from the root:

mkdir /home/username/newfolder

Understanding paths is crucial for effective folder creation.

Creating Folders With Timestamps

For backup scripts or organized logging, you might want folders with date-based names:

mkdir backup_$(date +%Y%m%d)

This creates a folder like “backup_20241115” based on the current date. You can customize the date format to suit your needs.

Using Variables For Folder Names

Bash variables make dynamic folder creation easy:

project_name="website"
mkdir $project_name

You can combine variables with other commands for powerful automation.

Creating Folders In Scripts

When writing shell scripts, always check if a folder exists before creating it:

if [ ! -d "$folder_name" ]; then
    mkdir "$folder_name"
fi

This prevents errors if the folder already exists. It’s a best practice for robust scripts.

Using Mkdir With Other Commands

You can combine mkdir with other commands using pipes and redirection. For example, creating folders from a list:

cat folderlist.txt | xargs mkdir

This reads folder names from a text file and creates each one. It’s perfect for batch operations.

Common Mistakes And How To Avoid Them

New users often make these errors:

  • Forgetting the folder name – mkdir with no arguments shows an error
  • Using invalid characters like / in names
  • Not having write permissions in the target directory
  • Typing “mrdir” or “mkdri” instead of mkdir

Always double-check your command before pressing Enter. Use the Tab key for autocompletion to avoid typos.

Creating Folders With GUI File Manager

Not everyone prefers the command line. Most Linux desktop environments let you create folders visually:

  • Open your file manager (Nautilus, Dolphin, Thunar, etc.)
  • Navigate to where you want the folder
  • Right-click and select “New Folder” or “Create Folder”
  • Type the name and press Enter

This method is identical to creating folders on Windows or macOS. It’s intuitive and requires no commands.

Keyboard Shortcuts For GUI Creation

Most file managers support keyboard shortcuts:

  • Ctrl+Shift+N – Creates a new folder in Nautilus (GNOME)
  • F10 then select New Folder – Works in many managers
  • Ctrl+Shift+Alt+N – Some custom configurations

Learning these shortcuts speeds up your workflow significantly.

Creating Temporary Folders

For temporary files, use the mktemp command:

mktemp -d

This creates a unique temporary folder in /tmp with a random name. It’s perfect for scripts that need scratch space.

Folder Creation In Different Directories

You can create folders in system directories, but you’ll need superuser privileges:

sudo mkdir /opt/myapp

Be careful when creating folders outside your home directory. Incorrect permissions can break system functionality.

Using Brace Expansion

Bash brace expansion creates multiple folders with patterns:

mkdir {jan,feb,mar}_reports

This creates “jan_reports”, “feb_reports”, and “mar_reports” in one command. You can combine braces with numbers:

mkdir chapter{1..5}

This creates chapter1 through chapter5 folders.

Creating Hidden Folders

Hidden folders start with a dot. They don’t appear in regular directory listings:

mkdir .config

Use ls -a to see hidden folders. They’re commonly used for application settings.

Folder Creation With Find Command

Advanced users can create folders based on file patterns:

find . -type f -name "*.txt" -exec mkdir -p {}.dir \;

This creates a folder for each text file found. It’s complex but powerful for specific use cases.

Understanding Directory Structure

Linux uses a hierarchical directory structure. Every folder except root has a parent. When you create folders, consider how they fit into the overall structure.

Common directories include:

  • /home – User home directories
  • /tmp – Temporary files
  • /var – Variable data like logs
  • /opt – Optional software packages

Permissions And Ownership

When you create a folder, you become its owner. Use chmod to change permissions and chown to change ownership:

chmod 755 myfolder
sudo chown user:group myfolder

Proper permissions prevent unauthorized access to sensitive data.

Creating Symbolic Links To Folders

Sometimes you want a shortcut to a folder instead of copying it:

ln -s /path/to/original linkname

This creates a symbolic link that acts like the original folder. It’s useful for organizing files without duplication.

Automating Folder Creation With Cron

Schedule regular folder creation using cron jobs:

0 0 * * * mkdir -p /backups/$(date +\%Y\%m\%d)

This creates a dated backup folder daily at midnight. Adjust the schedule to fit your needs.

Using Mkdir In One-Liners

Combine mkdir with other commands for efficient workflows:

mkdir newproject && cd newproject && touch readme.md

This creates a folder, enters it, and creates a file in one line. The && ensures each command runs only if the previous succeeded.

Creating Folders With Special Characters

Some characters need escaping in folder names:

  • Spaces – Use quotes or backslashes
  • Dollar signs – Escape with backslash
  • Apostrophes – Use double quotes around the name
  • Parentheses – Escape or quote

Example: mkdir "John's Files (2024)"

Recursive Folder Deletion

To remove folders you created, use rmdir for empty folders or rm -r for folders with contents:

rmdir emptyfolder
rm -r fullfolder

Be extremely careful with recursive deletion. There’s no undo in the terminal.

Folder Creation In Virtual Environments

When using Python virtual environments or Docker containers, folder creation follows the same rules. The mkdir command works identically inside these environments.

Best Practices For Folder Organization

Follow these guidelines for maintainable folder structures:

  • Use descriptive names that explain contents
  • Avoid spaces in names when possible (use underscores or hyphens)
  • Keep hierarchy shallow (no more than 3-4 levels deep)
  • Use consistent naming conventions across projects
  • Document your structure for team projects

Common Use Cases

Here are typical scenarios where you’ll create folders:

  • Setting up a new project structure
  • Organizing downloaded files
  • Creating backup directories
  • Preparing web server document roots
  • Structuring source code repositories

Troubleshooting Folder Creation

If mkdir fails, check these common issues:

  • Disk space – Run df -h to check available space
  • Permissions – Use ls -ld to check directory permissions
  • Invalid characters – Avoid /, null characters, and trailing dots
  • File system limits – Some filesystems have maximum name lengths

Advanced: Creating Folders With Extended Attributes

Some filesystems support extended attributes. You can set them during creation:

mkdir newfolder
setfattr -n user.comment -v "Project files" newfolder

This adds metadata to the folder that can be queried later.

Using Mkdir With SSH

Create folders on remote servers:

ssh user@server "mkdir /remote/path/newfolder"

This runs mkdir on the remote machine. Combine with SCP for file transfers.

Folder Creation In Different Shells

While mkdir works in bash, zsh, and fish, some shells have additional features. Zsh offers enhanced globbing and completion for folder creation.

Performance Considerations

Creating folders is generally fast, but on large filesystems with millions of files, operations can slow down. Use time command to measure performance:

time mkdir -p a/b/c/d/e/f

Security Implications

Be mindful when creating world-writable folders (permissions 777). They can be exploited by malicious users. Always use the minimum permissions necessary.

Creating Folders With ACLs

Access Control Lists provide finer permission control:

mkdir aclfolder
setfacl -m u:username:rwx aclfolder

This gives specific users custom permissions beyond standard Unix permissions.

Integration With Version Control

When creating folders for Git repositories, remember that Git tracks files, not empty folders. Add a .gitkeep file to preserve empty directories:

mkdir emptydir
touch emptydir/.gitkeep

Cross-Platform Considerations

If you share folders with Windows systems, avoid characters like :, <, >, ?, and |. Use short names without spaces for maximum compatibility.

Learning More

Explore the mkdir manual page for complete options:

man mkdir

Practice regularly to build muscle memory. The command becomes second nature with repetition.

Frequently Asked Questions

What Is The Command To Make A Folder In Linux?

The command is mkdir followed by the folder name. For example, mkdir myfolder creates a folder named myfolder in the current directory.

How Do I Create Multiple Folders At Once In Linux?

Use mkdir folder1 folder2 folder3 to create multiple folders in one command. You can also use brace expansion like mkdir {a,b,c} for pattern-based creation.

Can I Create A Folder With Spaces In The Name?

Yes, use quotation marks: mkdir "My Folder" or escape spaces: mkdir My\ Folder. Both methods work correctly.

How Do I Create A Folder In A Different Directory?

Specify the full path: mkdir /home/user/newfolder or use relative paths like mkdir ../sibling. The command works from any location.

What Does The -P Flag Do In Mkdir?

The -p flag creates parent directories as needed. For example, mkdir -p a/b/c creates a, b, and c directories if they don’t exist, without errors.

Mastering folder creation is a fundamental skill for any Linux user. Start with simple commands and gradually explore advanced options. With practice, you’ll create directories quickly and efficiently, keeping your files organized and accessible.

Remember to always verify your commands before executing them, especially when using sudo or recursive operations. Happy organizing!