Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Create and Delete Folders in Linux Terminal

Learn about Linux, including how to Create Folders Using Command Line, key uses, practical steps, common issues, and answers to frequently asked questions.

Table of Contents

This practical guide explains how to create and delete folders in linux terminal with clear steps and useful context. It also covers common requirements, potential problems, and the details that can help you get better results.

If you're a Linux enthusiast and want to master creating and managing folders from the command line, here's what you need to know.

How to Create Folders Using Command Line

The mkdir command holds the key to all your directory creation tasks. You can create one or more folders in terminal with one line of code. Here's how the mkdir command on Linux works:

1. Create a Single Directory on Linux

Here's how you can use the mkdir function to create a directory:

mkdir [option] 

For example, if you want to create a new directory, you can use the following command:

mkdir MUO

The above command creates a new MUO folder in the current location. To navigate to the MUO directory via the command line, you can use the cd command:

cd ./MUO

1. Create a Single Directory on Linux - Linux

The cd command is a very flexible way to change directories in the Linux terminal.

2. Create Multiple Folders on Linux

The mkdir function is very flexible, allowing you to create multiple directories with just one command. For example, to create multiple folders via command line, use the code below:

mkdir .

To create 3 directories, here is how you can use the mkdir command:

mkdir MUO_sample1 MUO_sample2 MUO_sample3

When you run the above command, the program will create 3 folders: MUO_sample1, MUO_sample2 and MUO_sample3. You can run the ls command to list newly created directories.

2. Create Multiple Folders on Linux - Linux

The Linux directory structure is complex, so it's best to familiarize yourself with parent and child directories to avoid unnecessary hurdles.

3. Create Folders Directly

As a Linux user, you can create folders directly at the desired location. You do not need to navigate to the location or use the mkdir function in the terminal.

All you need to do is go to the folder/location where you want to create a new folder/folder and right click.

From the list menu, click on the New Folder option.

3. Create Folders Directly - Linux

When you see the new folder icon, you can rename the folder to a name of your choice.

3. Create Folders Directly - Linux

Rest assured, if you want to check the directory status from a terminal window, you can still use the cd command to navigate to a specific location and run the ls command to list the contents.

Mkdir Options

You can use several options with the mkdir command, which help you enhance the command's existing utility. You can use the commands listed below:

1. -p or -parents : The -p command is useful when creating parent folders and child folders together. If the specified parent folder already exists, it will automatically create subfolders.

mkdir -p MUO/MUO_CHILD

Mkdir Options - Linux

2. -v or -verbose : The -v command adds verbose messages to each directory created.

mkdir - v file1 file2

Mkdir Options - Linux

3. --version : The --version command outputs license version details.

mkdir --version

Mkdir Options - Linux

Delete Empty and Non-Empty Linux Folders

Finally, once you have created folders on your Linux operating system, you may want to delete those you no longer need. You can delete folders on your Linux operating system in two ways:

  • rm
  • rmdir

Let's discuss both these methods in detail!

If you want to delete empty and non-empty folders, you can use the rm command as follows:

1. Check the Contents of the Folder

Before deleting a folder, you should check its contents. To do so, navigate to the folder's location using the cd command.

cd ./MUO

In the example above, MUO is a folder on the Ubuntu Desktop.

2. List Directory Contents

Once you are in the directory's location, use the ls command to list the directory's contents.

ls

2. List Directory Contents - Linux

The command lists all the contents of a directory. You will see a list of all files stored in this folder on your screen.

3. Delete the Folder Via Terminal

Enter the command rm, followed by the various commands and the name of the folder you want to delete.

rm -option 

You can use the ls command again to confirm the directory is no longer there.

Here are some of the most commonly used options with the rm command:

  • -f: Force deletion of files and folders from the directory
  • -i: Request permissions before deleting folders
  • -r: Delete stored directories and files recursively
  • -d: Delete empty directory

You can even remove multiple folders in one go. For example, when you want to delete the folders MUO_sample1, MUO_sample2, and MUO_sample3 with one command, here's how you can do it:

rm -d MUO_sample1 MUO_sample2 MUO_sample3

3. Delete the Folder Via Terminal - Linux

There is an alternative method you can use to delete empty folders. You can use the rmdir command to quickly delete directories as follows:

rmdir 

To delete the MUO3 folder when it does not have any files/subfolders in it, you can use the rmdir command as shown below:

rmdir MUO3

However, if the directory is not empty, you will receive an error message whenever you try to delete the directory using the rmdir command.

3. Delete the Folder Via Terminal - Linux

Note : Use rm and rmdir commands with care because deleted directories cannot be retrieved.

4. Delete Folder Directly

According to the way you create the folder, you can even delete that folder/folder directly. Select the folder you want to delete and press the Delete button on the keyboard. Make sure you check the folder's contents before deleting it, as this method is permanent.

Conclusion

Understanding Linux makes it easier to compare options, avoid common mistakes, and apply the information in this guide more effectively. Review the relevant requirements before making changes or choosing a solution.

FAQ

How do you create and delete folders in linux terminal?

Follow the steps in this guide in order, confirm the required settings or tools, and verify the result before making additional changes.

Is it safe to create and delete folders in linux terminal?

It is generally safe when you follow the recommended instructions, use trusted tools, and avoid changing settings you do not understand.

What should you do if the process does not work?

Recheck the requirements, restart the device or application when appropriate, and review each step for missed settings or compatibility issues.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.