How to Create a Directory from the Command Line in Linux

How to Create a Directory from the Command Line in Linux

If you’re going to spend much time at the command line, it’s essential that you know how to create directories and subdirectories on Linux (and other operating systems). But don’t worry—it’s not as hard as it seems. With just a few simple commands, you can be on your way to creating directories in no time at all!

cd /

The first step is to open up a terminal. You can do this by pressing Ctrl+Alt+T on your keyboard. Once the terminal is open, you’ll need to change directories to the root directory. You can do this by typing cd / into the terminal and pressing Enter. Now that you’re in the root directory, you can type mkdir folder_name to create a new folder with the name of folder_name. It’s not necessary to add the ending period if you don’t want to; just typing mkdir will be enough. Remember to include the quotes if you want it to take effect immediately without confirmation. For example, mkdir test.

One thing to keep in mind is that only certain characters are allowed when naming folders. Spaces are not allowed, but periods are. Another important thing is that folders cannot have the same name as any of its parent folders, so be careful when choosing names for your folders!


mkdir directoryname

You can create a directory from the command line in Linux using the mkdir command. The mkdir command takes a single argument, which is the name of the directory you want to create. To get started, open up your terminal and type:

If you are running Ubuntu or another Debian-based distribution, your default root directory will be /home/username/. For example:

If you are running Fedora or another Red Hat-based distribution, your default root directory will be /root/. For example:

In this case we are running Fedora so our root directory is /root/. As before we will run the following command

Now if we list out our directories with ls -a we should see that there is now a new one called mydirectory. Congratulations! You have just created a directory on the command line.


cd into your new directory

cd is the command to change directories. In order to make a new directory, we can use the mkdir command. Let’s say we want to make a directory called mydirectory. We would type the following into our command line: mkdir mydirectory This will create an empty directory with the name of mydirectory. To add files to this directory and make it readable by other users on your system, you must give ownership of the files you add to it. The chown command (short for change owner) will let you do that: chown username mydirectory Change the username argument to match yours and enter the directory’s path for mydirectory.


To remove the new directory, execute rm -rf with the path as well.

If there are subdirectories in your current location or destination, you may have to add -r (for recursive) if using rm or rmdir instead of just rm. To delete directories without confirmation, simply use the -f option at the end of rm or

rmdir. To create a directory, you can use either mkdir or mkdirs. A difference between the two is that when making multiple directories, mkdirs will not overwrite existing directories unless the user requests it. When deleting these same sets of directories with rm -rf, however, only one prompt appears.


ls -a

Listing all of the files in a directory can be done using the ls command. The -a option tells ls to show all files, even hidden ones. If you just want to see a list of directories, use ls -d. For more information on ls, consult the man pages or type man ls at the command line. To create a new directory, we will use mkdir with the name of the new folder we would like to create as an argument. So, if I wanted to create a new folder called lunch I would enter mkdir lunch and press enter. To change into this newly created directory, I could do cd lunch.


When working with multiple directories it is important to know how to navigate back up the hierarchy tree so that you don’t get lost. To go up one level (to your home directory), use cd … To go back two levels up (into your home directory), use cd ../..

The other way is to have a shortcut for navigating back up one level when you are inside any subdirectory by using cd . As long as you’re still on the same hard drive, you should find yourself back in your home directory.

Get Started with Low-code Platforms: A Cheat Sheet Previous post Get Started with Low-code Platforms: A Cheat Sheet
The Best iPhone Deals and Contracts in July 2022: Get a New iPhone for Less! Next post The Best iPhone Deals and Contracts in July 2022: Get a New iPhone for Less!

Leave a Reply

Your email address will not be published. Required fields are marked *