Skip to main content

Command Palette

Search for a command to run...

How to Create a Folder in Linux

Updated
6 min read

Creating folders in Linux is a basic yet essential skill for organizing your files and managing your system efficiently. Whether you’re new to Linux or just need a quick refresher, understanding how to create directories can help you keep your workspace tidy and accessible. In this guide, I’ll walk you through the most common methods to create folders in Linux, using both the command line and graphical interfaces.

You’ll find step-by-step instructions, useful tips, and examples that make it easy to follow along. By the end, you’ll be comfortable creating folders in any Linux environment, whether you prefer typing commands or clicking through menus.

Understanding Linux Directories and Folders

In Linux, folders are called directories. They serve the same purpose as folders in other operating systems: to store and organize files. Directories can contain files or other directories, creating a hierarchical structure that helps you manage data efficiently.

Here are some key points about Linux directories:

  • Directories are part of the file system tree, starting from the root directory /.
  • You can create directories anywhere you have permission.
  • Directory names are case-sensitive.
  • Special characters like spaces can be used but often require escaping or quoting in commands.

Knowing these basics helps you avoid common mistakes when creating folders.

Creating a Folder Using the Command Line

The most common way to create a folder in Linux is by using the mkdir command. This command stands for "make directory" and is simple to use.

Basic mkdir Usage

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 mydocuments

This command creates a folder named mydocuments 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 saves time when you need multiple directories.

Creating Nested Folders

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

mkdir -p parentfolder/childfolder/grandchildfolder

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

Handling Spaces in Folder Names

If your folder name has spaces, enclose it in quotes or escape the spaces:

mkdir "my folder"
mkdir my\ folder

Both commands create a folder named my folder.

Checking Folder Creation

After creating a folder, you can verify it with the ls command:

ls -l

This lists the contents of the current directory, showing your new folder.

Using Graphical User Interface (GUI) to Create Folders

If you prefer not to use the terminal, most Linux desktop environments provide easy ways to create folders using the GUI.

Creating Folders in GNOME

GNOME is a popular desktop environment. To create a folder:

  1. Open the file manager (called "Files").
  2. Navigate to the location where you want the new folder.
  3. Right-click on an empty space.
  4. Select "New Folder" from the context menu.
  5. Enter the folder name and press Enter.

Creating Folders in KDE Plasma

KDE Plasma users can follow similar steps:

  1. Open Dolphin, the file manager.
  2. Go to the desired directory.
  3. Right-click and choose "Create New" > "Folder".
  4. Name your folder and hit Enter.

Keyboard Shortcuts

Many file managers support shortcuts like Ctrl + Shift + N to create a new folder quickly.

Managing Permissions When Creating Folders

Sometimes, you might get a "Permission denied" error when creating folders. This happens if you don’t have write access to the directory.

Checking Permissions

Use the ls -ld command to check permissions of a directory:

ls -ld /path/to/directory

Permissions are shown as a string like drwxr-xr-x. The first character d means it’s a directory.

Using sudo to Create Folders as Root

If you need to create a folder in a system directory, prefix the command with sudo:

sudo mkdir /usr/local/myfolder

This runs the command with administrative privileges.

Changing Folder Permissions

After creating a folder, you might want to change its permissions using chmod or change ownership with chown.

Advanced Tips for Creating Folders in Linux

Here are some additional tips to help you work more efficiently with folders:

  • Use variables: You can use shell variables to create folders dynamically.

    foldername="project_$(date +%Y%m%d)"
    mkdir "$foldername"
    
  • Create folders with specific permissions: Use mkdir -m to set permissions at creation.

    mkdir -m 755 newfolder
    
  • Automate folder creation: Write scripts to create multiple folders based on your needs.

  • Use tab completion: When typing folder names in the terminal, press Tab to auto-complete names.

Troubleshooting Common Issues

Sometimes, creating folders doesn’t go as planned. Here are solutions to common problems:

  • Permission denied: Use sudo or check directory permissions.
  • Folder already exists: Use mkdir -p to avoid errors if the folder exists.
  • Invalid characters in folder names: Avoid characters like /, \0, or control characters.
  • Spaces causing issues: Always quote folder names with spaces.

Summary Table: Common mkdir Commands

CommandDescription
mkdir foldernameCreate a single folder
mkdir folder1 folder2Create multiple folders
mkdir -p parent/childCreate nested folders
mkdir -m 700 securefolderCreate folder with specific permissions
sudo mkdir /protected/folderCreate folder with root privileges

Conclusion

Creating folders in Linux is straightforward once you know the right commands and methods. Whether you prefer using the terminal or the graphical interface, you have plenty of options to organize your files effectively. The mkdir command is your go-to tool for quick folder creation, and with options like -p and -m, you can handle complex directory structures and permissions easily.

Remember to check your permissions if you run into errors and use sudo when necessary. With these skills, managing your Linux file system becomes much easier, helping you stay organized and productive.

FAQs

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

Use the mkdir foldername command in your terminal. Replace foldername with your desired folder name.

Can I create multiple folders at once in Linux?

Yes, you can create multiple folders by listing them after mkdir, like mkdir folder1 folder2 folder3.

What does the -p option do in mkdir?

The -p option creates parent directories as needed, allowing you to create nested folders in one command.

How do I create a folder with spaces in its name?

Enclose the folder name in quotes, like mkdir "my folder", or escape spaces with a backslash, like mkdir my\ folder.

What should I do if I get a permission denied error when creating a folder?

Check your permissions with ls -ld. If needed, use sudo mkdir foldername to create the folder with administrative rights.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts