Skip to main content

Command Palette

Search for a command to run...

How to Create Folders in Linux

Updated
6 min read

Creating folders in Linux is a basic but essential skill for organizing your files and directories. Whether you're a beginner or someone who uses Linux regularly, knowing how to create folders quickly can save you time and keep your system tidy. In this article, I'll guide you through different methods to create folders in Linux, from using the command line to graphical interfaces.

You’ll learn simple commands, tips for creating multiple folders at once, and how to manage folder permissions. By the end, you’ll feel confident managing your Linux directories like a pro.

Understanding Folders and Directories in Linux

In Linux, folders are often called directories. They serve as containers to store files and other directories. Organizing your files into folders helps keep your system clean and makes it easier to find what you need.

Linux treats everything as a file, including directories. This means you can use commands to create, move, and delete folders just like files. The most common way to create folders is through the terminal, but graphical tools are also available.

Here’s why knowing how to create folders matters:

  • Keeps your files organized and easy to access.
  • Helps manage permissions and security.
  • Supports scripting and automation for repetitive tasks.

Creating Folders Using the Command Line

The command line is the most powerful and flexible way to create folders in Linux. The main command you’ll use is mkdir, which stands for "make directory."

Basic Folder Creation with mkdir

To create a single folder, open your terminal and type:

mkdir foldername

Replace foldername with the name you want for your folder. For example:

mkdir Documents

This command creates a folder named "Documents" in your current directory.

Creating Multiple Folders at Once

You can create several folders in one command by listing them separated by spaces:

mkdir folder1 folder2 folder3

This creates three folders named folder1, folder2, and folder3 simultaneously.

Creating Nested Folders

Sometimes, you want to create a folder inside another folder that doesn’t exist yet. Use the -p option with mkdir to create parent directories as needed:

mkdir -p parentfolder/childfolder/grandchildfolder

This command creates all three folders in one go, even if parentfolder or childfolder don’t exist.

Checking Folder Creation

After creating folders, you can verify by listing the contents of your current directory:

ls -l

This shows all files and folders with details, so you can confirm your new folders are there.

Managing Folder Permissions When Creating Folders

Linux uses permissions to control who can read, write, or execute files and folders. When you create a folder, it gets default permissions based on your system settings.

Setting Permissions with mkdir

You can set specific permissions at folder creation using the -m option:

mkdir -m 755 foldername

Here, 755 means:

  • Owner can read, write, and execute.
  • Group and others can read and execute but not write.

This is a common permission setting for folders.

Understanding Permission Numbers

Permissions are represented by three digits:

  • First digit: Owner permissions.
  • Second digit: Group permissions.
  • Third digit: Others permissions.

Each digit is a sum of:

  • 4 for read (r)
  • 2 for write (w)
  • 1 for execute (x)

For example, 700 means only the owner has full access.

Creating Folders Using Graphical User Interfaces (GUI)

If you prefer not to use the terminal, most Linux desktop environments offer easy ways to create folders through graphical tools.

Using File Managers

Popular Linux file managers include Nautilus (GNOME), Dolphin (KDE), and Thunar (XFCE). Here’s how to create folders using them:

  • Open your file manager.
  • Navigate to the location where you want the new folder.
  • Right-click on an empty space.
  • Select "New Folder" or "Create Folder."
  • Enter the folder name and press Enter.

This method is intuitive and works well for users who prefer visual interfaces.

Keyboard Shortcuts

Many file managers support shortcuts to create folders quickly:

  • In Nautilus, press Ctrl + Shift + N.
  • In Dolphin, press F10.

These shortcuts save time when organizing files.

Automating Folder Creation with Scripts

If you need to create many folders regularly, scripting can automate the process.

Simple Bash Script Example

Create a file named create_folders.sh with the following content:

#!/bin/bash
mkdir -p Project/{Docs,Src,Tests}

This script creates a Project folder with three subfolders: Docs, Src, and Tests.

Make the script executable:

chmod +x create_folders.sh

Run it with:

./create_folders.sh

This saves time and reduces errors when setting up folder structures.

Using Loops for Multiple Folders

You can also use loops to create folders with numbered names:

for i in {1..5}; do
  mkdir "Folder_$i"
done

This creates folders named Folder_1 to Folder_5.

Troubleshooting Common Issues When Creating Folders

Sometimes, you might face problems creating folders. Here are common issues and how to fix them:

  • Permission Denied: You don’t have rights to create folders in the target location. Use sudo for administrative access:

    sudo mkdir foldername
    
  • Folder Already Exists: The folder name is taken. Choose a different name or delete the existing folder.

  • Invalid Characters: Avoid using special characters like /, \, or * in folder names.

  • Path Too Long: Some systems limit path length. Keep folder names concise.

Best Practices for Naming Folders in Linux

Good folder names improve organization and avoid errors. Here are tips:

  • Use lowercase letters and numbers.
  • Separate words with underscores _ or hyphens -.
  • Avoid spaces and special characters.
  • Keep names descriptive but short.
  • Use consistent naming conventions across projects.

For example, use project_docs instead of Project Docs.

Summary Table: mkdir Command Options

OptionDescriptionExample
mkdir foldernameCreates a single foldermkdir myfolder
mkdir folder1 folder2Creates multiple foldersmkdir folder1 folder2
mkdir -p path/to/folderCreates nested foldersmkdir -p a/b/c
mkdir -m 700 foldernameCreates folder with specific permissionsmkdir -m 700 secret

Conclusion

Now you know how to create folders in Linux using both the command line and graphical tools. The mkdir command is your go-to for quick and flexible folder creation, especially when combined with options like -p and -m. If you prefer visual methods, file managers make it easy to create folders with just a few clicks.

Remember, organizing your files into folders helps keep your system neat and efficient. You can also automate folder creation with simple scripts to save time. With these skills, managing your Linux directories will become second nature.

FAQs

How do I create a folder in Linux using the terminal?

Use the mkdir command followed by the folder name, like mkdir foldername. This creates a new folder in your current directory.

Can I create multiple folders at once in Linux?

Yes, you can create several folders by listing their names separated by spaces: mkdir folder1 folder2 folder3.

How do I create nested folders in Linux?

Use the -p option with mkdir, like mkdir -p parent/child/grandchild, to create nested folders in one command.

How do I set permissions when creating a folder?

Use the -m option with mkdir to set permissions, for example, mkdir -m 755 foldername sets specific read, write, and execute permissions.

What should I do if I get a "Permission Denied" error?

Try running the command with sudo to gain administrative rights: sudo mkdir foldername. Make sure you have the necessary permissions for the target location.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts