Skip to Content

2 ways to create a directory in Linux

This article is part of the following series.

 

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!

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!