How to Create a Directory in Linux? (A Comprehensive Guide: Create a Folder in Linux)

Posted on

How to Create a Directory in Linux? (A Comprehensive Guide: Create a Folder in Linux)


In Linux, a directory is a location to store files and subdirectories. Think of it like a folder in Windows. Linux/Unix operating systems are heavily directory-oriented. This guide will cover commands used to create and manage directories for both beginners and system administrators.


Linux excels in stability and versatility, simplifying many tasks. Its terminal is a key feature, enabling command execution for system modifications and software downloads.


This tutorial explores different commands and options for creating directories (folders) using the terminal, specifically the “mkdir” command to create single or multiple directories.


Prerequisites


Before using the “mkdir” command, ensure you meet these prerequisites:


1. A running Linux or Unix-like operating system with access to the command-line “terminal” for executing commands.


2. “sudo” privileges and read/write access to create new directories.


Linux “mkdir” Command (Make Folder in Linux)


The “mkdir” command in Linux is used to create directories. You can create single or multiple directories at once, and set permissions for specific directories.


To create a subdirectory, users need read/write permissions on the parent directory. Otherwise, a


“permission denied”


error will occur.


Basic Syntax of the “mkdir” Command


The basic syntax for creating a directory using “mkdir” is:

                                    
                                        $ mkdir [option] [directories]
                                    
                                




How to Create a Directory in Linux? (Linux Create Directory)




The


“mkdir” command in Linux


is used to create a new directory or folder. To create a directory, execute the “mkdir” command and specify the directory name:

                                    
                                        $ mkdir directory_name
                                    
                                


For example, to create a directory named “testdirectory”:

                                    
                                        $ mkdir testdirectory
                                    
                                






This creates “testdirectory” in your current working directory. You can confirm your location using the “pwd” command:

                                    
                                        $ pwd
                                    
                                






To create the directory in a *different* location, specify the full path:


$ mkdir /path-to-directory directory_name

                                    
                                        $ mkdir /home/samreena/Documents/testdirectory
                                    
                                


This creates the “testdirectory” folder within the `/home/samreena/Documents/` directory.


Linux “mkdir” Command with Options


The


“mkdir”


command supports various options to customize directory creation. You can create multiple directories, set permissions, and more.


Here are some useful “mkdir” commands with different options:


Command


Description


mkdir dir_name


Creates a single directory in the current directory.


mkdir {dir1,dir2,dir3,dir4}


Creates multiple directories in the current location. No spaces inside the {}.


mkdir –p dir/path/new_dir

Share this: