Wednesday 18 May 2011

mkdir command


Brief: This command is used to create a new directory/folder in a linux system.

Syntax: mkdir directoryname

Command: mkdir newfolder

Description:

The mkdircommand will create a new directory in present working directory. If the user is working in /home/username/ directory then new folder will be created in  /home/username/newfolder .

User can also specify the path where the new directory needs to be created in the mkdir command.
For ex: Assume that user is presently working in  /home/username/newfolder , but  wants to create a new directory with name student in /home/class/ then following command will do.
mkdir /home/class/student/
Here it is assumed that home and student directory already exist. If any folder in the path mentioned does not exist then an error will be shown and directory will not be created.

What if the directory already exists in present working directory?
User will get an error message saying that directory already exists.

Arguments:

-p : This argument creates the non existing parent directories also along with the leading directory.
Command :  mkdir -p /home/class/student/result
In above command if class and student directory does not exist then they will be created along with result directoy.

-v : Displays the log message for each directory created. This parameter is mostly used -p parameter to get information about the new directory created.

Important Examples:

1. Create one or more directory in a single command. Try below command
    mkdir /home/user/student /home/user/teacher/

2. Create parent directories and print message against each directory created.
   mkdir -pv /home/user/student/classes/bca
   

No comments:

Post a Comment