Thursday 9 October 2014

mkdir command

 

This command is used to create a new directory. The various formats of the command are as follows

mkdir <directory_name> ......

This will create a new directory with the name “directory_name” in the current directory.

mkdir <path/directory_name> .....

This will create a new directory with the name “directory_name” in the specified path. The parent directories should exist for this to work properly. Otherwise it will throw error.

mkdir -m <MODE> [other options] <directory_name> ... | <path/directory_name> ...

OR

mkdir -m<MODE> [other options] <directory_name> ... | <path/directory_name> ...

This will create a new directory with the name “directory_name” in the current directory or specified path with the permission as specified by the “MODE” value. If other options (except –help and –version) are specified “mkdir” will take care of that also while creating directories.

mkdir -p [other options] <path/directory_name> ...

This will create a new directory with the name “directory_name” in the specified path with the creation of parent directories as needed. If the parent directory already exists, there is no problem. If it doesn't the command will create the directory. If other options (except –help and –version) are specified “mkdir” will take care of that also while creating directories.

mkdir -v [other options] <directory_name>... | <path/directory_name>...

A message is outputted for each of the created directories. If the directory already exists no message is shown.

mkdir –-help

Shows the help for the command

mkdir –-version

Shows the version of the command

Creating multiple directories at a stretch

mkdir <directory1> <directory2> <path/directory3> ....

This will create all the directories. You can use any options (except –help and --version) of the “mkdir” command along with this.

Examples

Creating a directory named “test” in the current directory.

mkdir test

Creating a directory named “test” in the directory “/tmp/testabc/”. The directories “/tmp” and “/tmp/testabc” already exists.

mkdir /tmp/testabc/test

Creating a directory named “test” in the current directory with permission 644

mkdir -m644 test

Creating a directory named “test” in the directory “/tmp/testabc/” with permission 555. The directories “/tmp” and “/tmp/testabc” already exists.

mkdir -m555 /tmp/testabc/test

Creating a directory named “test” in the path “/testabc/hai/monday/week/day”. None of the directories in the path exists, except “/”

mkdir -p /testabc/hai/monday/week/day/test

Creating a directory named “hello” in the path “/hai/month/week/day” with permission 700. None of the directories in the path exists, except “/”

mkdir -pm700 /hai/monday/week/day/hello

No comments:

Post a Comment