2 ways to create a directory in Linux (2024)

This article is part of the following series.

  • 2 ways to create a directory in Linux
  • How to Get the current directory in Linux
  • 4 Ways to Check the size of a directory in Linux

Creating directories in Linux can be a little tricky, especially if you are not familiar with the command line. In this blog post, we will discuss two different ways to create directories in Linux: using the mkdir command and using the GUI.

We will also provide tips on how to make it easier for you to create directories in Linux!

Table of Contents

Procedures to create a directory in Linux

  • Open the terminal
  • Type mkdir newdir to create a new directory called newdir.
  • Type ls -l to view a list of all the files and directories in the current directory, which should now include the newdir directory you just created.
  • Type cd newdir to change into the new directory.
  • Type touch test.txt to create a new file called test.txt in the new directory.
  • Type ls -l to view a list of all the files and directories in the current directory, which should now include the test.txt file you just created.

what is directory in Linux

A directory in Linux is a type of file system object that can be used to organize files. A directory can contain files and other directories. It is similar to a folder in Windows.

Directories are used to organize files in a hierarchical structure, similar to the way that a tree is organized with branches and leaves.

Each directory in Linux has a name and a path. The name is used to identify the directory within its parent directory, and the path is used to locate the directory in the file system.

The root directory in Linux is represented by a forward slash (/), and all other directories are organized under it. For example, the /home directory contains the user’s home directories, while the /var directory contains variable data files, such as log files.

Directories can be created, renamed, moved, copied, and deleted using various commands in Linux. The most common commands used for working with directories are mkdir (to create a directory), rmdir (to remove an empty directory), ls (to list the contents of a directory), cd (to change the current directory), and pwd (to display the current directory).

create a directory with mkdir command in Linux

You can easily create a directory in Linux using mkdir command. Open the default terminal and type in the following command: mkdir directory_name. Replace directory_name with the name of the directory you want to create. Press enter. The new directory will be created under the current directory.

For example, if you wanted to create a directory called “test”, you would type in the following command. This would create a test directory under the current directory.

mkdir test

You can then verify that the directory was created successfully using the ls command to list the contents of the current directory.

If you wanted to create a directory called “test” in the /home/user/Documents directory, you would type in the following command: mkdir /home/user/Documents/test. This would create a test directory in the /home/user/Documents directory

create multiple directories with mkdir command in Linux

You can also use the mkdir command to create multiple directories at once.

For example, if you wanted to create two directories called “test1” and “test2” in the current directory, you would type in the following command. This would create test1 and test2 directories in the current directory.

mkdir test1 test2

You can also specify the full path of each directory if you want to create them in different locations. For example:

mkdir /home/user1/dir1 /home/user2/dir2 /home/user3/dir3

This will create three directories named “dir1”, “dir2”, and “dir3” in different locations specified by their full paths.

create a parent directory in Linux

The -p option stands for “parents” and it tells the mkdir command to create any necessary parent directories that don’t already exist.

If you want to create a hierarchy of directories, you can use the -p option with the mkdir command. For example:

mkdir -p /home/user1/test/dir1

This will create a directory called “test” under the “user1” directory, and a directory called “dir1” under the “test” directory. The -p option tells the mkdir command to create any missing parent directories as necessary.

create a directory with GUI in Linux

You can also use the GUI to create directories in Linux. To do this, you will need to open your file manager. For example, if you are using the GNOME desktop environment, you would click on the “Files” icon that is located on the sidebar.

Once you have opened your file manager, you can create a new directory by clicking on the “New Folder” icon that is located in the toolbar. You can then type in a name for your new directory and click “Create”.

The exact steps may vary depending on the file manager you’re using, but the general process should be similar.

Tips to create directory in Linux

Try out these tips the when you need to create a directory in Linux! With these methods, you should be able to easily create directories without any trouble.

  • When creating a directory in Linux, it is important to make sure that the name is spelled correctly and that there are no spaces in the name.
  • You can use the -p option with the mkdir command to create any necessary parent directories.
  • The ls command can be used to list the files inside of a directory.

More Linux commands about directory in Linux

The following are some Linux commands that can be used to manage directories:

  • rmdir: This command is used to delete directories. It can only be used if the directory is empty.
  • rm: This command is used to delete files.
  • chmod: This command is used to change the permissions of files and directories.
  • chown: This command is used to change the owner of a file or directory.
  • mv: This command is used to move or rename files and directories.
  • cp: This command is used to copy files and directories.

Linux commands for directory

  • To create a new directory: mkdir my_new_directory
  • To change into a directory: cd my_new_directory.To move to a specific directory, use the cd /path/to/directory command. Remember to use proper pathnames when using the cd command. For example, if you want to move into the /usr/local directory, you would use the following command: cd /usr/local. To move up one level in the directory tree, use the cd .. command. To move to your home directory, use the cd ~ command.
  • To list the contents of a directory: ls -l
  • To find out your current working directory: pwd

How to find out what is taking up so much size in my home directory?

There are a few ways to find out what is taking up so much space in your home directory. You can use the “du” command to check the size of each file and directory. Or, you can use the find command to list all of the files that are larger than a certain size.

Creating directories in Linux can be a little tricky, especially if you are not familiar with the command line. In this blog post, we have discussed two different ways to create directories in Linux: using the mkdir command and using the GUI. We have also provided tips on how to make it easier for you to create directories in Linux! Try out these methods and see which one works best for you.

Thanks for reading and happy learning!

2 ways to create a directory in Linux (2024)

FAQs

How do you create a directory in Linux? ›

To create new directory use "mkdir" command. For example, to create directory TMP in the current directory issue either "mkdir TMP" or "mkdir ./TMP".

What are two ways to create directories at the command prompt? ›

To create a directory in MS-DOS or the Windows Command Prompt (cmd), use the md or mkdir MS-DOS command.

How do I create two directories in Linux? ›

To create more than one directory simultaneously, specify the names of the new directories after mkdir with a blank space between them: $ mkdir dir1 dir2 dir3 $ ls -l total 0 drwxrwxr-x. 2 localuser localuser 6 Jun 9 14:57 dir1 drwxrwxr-x. 2 localuser localuser 6 Jun 9 14:57 dir2 drwxrwxr-x.

How do I create two files in a directory in Linux? ›

Touch command can be used to create multiple numbers of files at the same time. These files would be empty while creation. Multiple files with name Doc1, Doc2, Doc3 are created at the same time using touch command here.

How do you create a user and directory in Linux? ›

You simply type adduser followed by the name of the user that you want to create. Once invoked, the command creates a new user and group that bears the username of the user being created. It then adds the user to the group and creates a home directory for the user.

What are the two types of directories? ›

Single-level directories and two-level directories are the two types of directories. The single-level directory is the simplest directory structure. In a two-level directory structure, there is a master node that has a separate directory for each user. Each user can store the files in that directory.

What is a directory in Linux? ›

In Linux®, a directory is a folder in which you store files. Each file or directory specifies which users can access them.

What are the two commands used to create a file in Linux terminal? ›

In this article, we will see three methods through which we can create files using the terminal. The three commands that we'll discuss are touch , cat and echo .

Which command is used to make a new directory? ›

The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md .

How to use mkdir command in Linux? ›

The mkdir stands for 'make directory'. With the help of mkdir command, you can create a new directory wherever you want in your system. Just type "mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and then press enter.

How do you create a new home directory in Linux? ›

By default, the useradd command does not create a home directory. Instead, you will need to specify the -m option to create a home directory for a user. This will create a home directory with username at /home/ and copy the . bash_logout, .

How do you create a new folder? ›

To make a new folder, simply open File Explorer and select Home in the upper-left corner of the window to find the New folder icon. A new folder will automatically appear on the screen, and you can rename the folder by right-clicking on the name.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Delena Feil

Last Updated:

Views: 6075

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.