What is the correct syntax for creating a parent directory and a child subdirectory?

Prepare for the LPI Linux Essentials Exam. Study with flashcards and multiple choice questions, each with hints and explanations. Get exam-ready!

The syntax for creating a parent directory and a child subdirectory is accurately represented by the command mkdir -p dir1/dir2. This command uses the -p option, which stands for "parents." When this option is included, mkdir will create the specified directory structure in a single command, including any necessary parent directories that do not already exist.

For instance, if dir1 does not exist, mkdir -p dir1/dir2 will create both dir1 and dir2 at the same time. This is particularly useful when you want to ensure that the hierarchy of folders is set up in one go without needing to create each level individually.

In contrast, simply using mkdir dir1 dir2 would attempt to create two directories at the same time, but it does not establish a parent-child relationship. The command mkdir dir1/dir2 would only work if dir1 already exists, as it will not create the parent directory if it is absent. Lastly, the command newdir dir1 dir2 is not a valid command in such context, as newdir is not a recognized command in standard Linux for creating directories.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy