How to create a directory in Linux

 

In order to create one or more than one directory in Linux we use the command mkdir. For creating a directory you type mkdir followed by the directory name.The command will create a new directory, provided a directory by the same name do not already exist. The syntax to create a directory in Linux is as shown below


Syntax:
mkdir directory_name
mkdir /path/to/directory 

Example:
mkdir my_documents

mkdir my_documents otherStuffs
mkdir my_documents/Pictures

The first method creates a directory by the name my_documents. In the second method two directories by the name my_documents and otherStuffs are created. The method creates a directory Pictures inside an already existing directory my_documents.

To create a directory within a new directory use -p flag along with mkdir. When used with -p flag command will check whether the parent directory exists. If not create the parent directory and then the sub-directory

Example:
mkdir -p my_documents/work
 
In the above case if there is no directory by the name my_documents in the current directory, a new directory my_documents will be created along with the sub-directory work

Comments

Popular posts from this blog

Understanding awk command with examples

what is UID and GID in Linux?

How to find serial number and other hardware details of Laptop/PC/Server from command line using dmidecode