Linux mkdir | Linux Create Directory

So now let’s learn to how we can create your own directory with the help of command prompt.

Here mkdir is the acronym for ‘make directory’. By using mkdir command, we can create a new directory anywhere in the system. You just need to type “mkdir <dir name> and type the name for a new directory you want to create in place of <dir name> and press enter.

Syntax:

mkdir <dirname>

Example: mkdir created

[email protected]:~$ pwd
 
/home/codes
 
[email protected]:~$ mkdir created
 
[email protected]:~$
 
[email protected]:~$ ls

Created Documents Music Public Untitled Folder

Desktop Downloads New Sreated Videos

Disk1 examples.desktop Pictures Templates

[email protected]:~$
 
[email protected]:~$ pwd
 
/home/codes
 
[email protected]:~$ mkdir created
 
mkdir: cannot create directory 'created': file exists
 
[email protected]:~$

So we are currently in /home/codes directory in the above example. After using the “mkdir created” command, a new directory named ‘created’ is created.

So mow if we here try to create a new file with the same file name ‘created’ that is already in existence then as you can see above, we get an error message.

Note: In order to create a directory at your required destination, provide the path of your destination directory or else the new directory will automatically be created in the current directory.

To make multiple directories

Syntax:

mkdir <dirname1> <dirname2> <dirname3> ...

Example:

[email protected]:~/created$ mkdir file1 file2 file3
 
[email protected]:~/created$
 
[email protected]:~/created$ ls
 
file1 file2 file3
 
[email protected]:~/created$

If you want to create multiple directories simultaneously, take a look at the above example as we have created multiple directories ‘file1 file2 file3’ at once.

Mkdir Options

OptionsDescription
mkdir -p, -parentsTo create a directory including its sub directory.
mkdir -v, -verboseTo print a message for each created directory.
Mkdir -m -mode=MODEUsed to set access privilege.

 

Content Protection by DMCA.com
Please Share