Here’s a review of the
mkdir command and the often overlooked
-p option from Easy Linux Commands by Terry Clark and I.
Creating New Directories
mkdir (make directory) command is used to create a new directory. The directory to be created can be referenced via an absolute path or via a relative path starting with the current working directory.
Make a directory using an absolute path:
$ mkdir /home/tclark/new_dir1
Make a directory using a relative path:
$ mkdir new_dir2
examples new_dir1 new_dir2
â€“p (parent) option allows creation of a complete directory branch when parent directories do not yet exist. This will actually create both the parent directory and subdirectory specified. In our example that means the new_dir3 and sub_dir3 are both created with a single command.
Make a new directory with a subdirectory using the
$ mkdir -p new_dir3/sub_dir3
examples new_dir1 new_dir2 new_dir3
$ ls new_dir3
Of course you can also list more than one directory to create with a single