How to Make a New Directory in Linux

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
You can make a directory in Linux.
Image Credit: TommL/E+/GettyImages

If you're used to user-friendly operating systems like Windows, the command-line interface used by Linux can lead to some confusion. Even relatively simple tasks, such as creating a new folder in your current location and navigating between folders, require the correct command-line code to complete. The good news is that it's relatively simple once you know the Linux create folder command. You can even make multiple nested directories or numerous directories in a single command.

Advertisement

Moving Between Folders in Linux

Video of the Day

Before you create a directory in Linux, navigate to the location you want the folder to be. You automatically start in your home directory, but if you're not sure where you are, you can use the "pwd" (print working directory) command to display your current location. You can also display the contents of the current directory using the "ls" command, which may be more helpful than knowing your current directory.

Advertisement

Video of the Day

If you need to go to another directory before creating your new one, use the "cd" command. For example, assume you want to navigate to "Documents," inside home and your user profile: type "cd /home/User/Documents" to go to the directory. To go back one directory, type "cd" without writing anything afterward.

Advertisement

Create Directory in Linux – 'mkdir'

The basic command to make a new directory is "mkdir" (literally "make directory"). This makes the new folder in your currently active directory, so you need to be in the right location before you use it. The command is easy to use: type the command, add a space and then type the name of the new folder.

Advertisement

So if you're inside the "Documents" folder, and you want to make a new folder called "University," type "mkdir University" and then select enter to create the new directory.

Making Nested Directories

To create a directory with subfolders in one command, add "-p" to the end of the "mkdir" command. This stands for "parent" and allows you to create as many nested directories as you want by writing out a file path like you do when navigating between directories.

Advertisement

Advertisement

For example, assume you want to create a folder called "English Literature" inside "Year 1" inside a "University" folder as in the previous example. You do this by typing "mkdir -p University/Year 1/English Literature" in the location where you want the path to start. If you run into problems relating to permissions, start the command with "sudo" and attempt again.

Advertisement

Making Multiple Directories

You can also use the "mkdir" command to create multiple directories in the same location. Do this by listing the names of all the folders separated by spaces after the command. For example, assume you want to create the folders "Music," "Games" and "Pictures" inside your current folder. Type "mkdir Music Games Pictures" in the command line and then select enter.

Advertisement

Check you've created the folders using the "ls" command, which should list all the new folders in addition to your older ones.

Advertisement

Advertisement

references