Can you create nested directories without `-p`?

QuestionsQuestions8 SkillsProDec, 15 2025
0124

Yes, you absolutely can create nested directories without the -p option, but it requires a slightly different approach.

When you don't use -p, the mkdir command expects that the parent directory (or directories) you're trying to create a new directory inside already exists.

So, to create maze/twisty/little/passages without -p, you would need to create each level of the directory structure individually, in order:

mkdir maze
mkdir maze/twisty
mkdir maze/twisty/little
mkdir maze/twisty/little/passages

If you try to directly run mkdir maze/twisty/little/passages without -p and if maze doesn't exist, you would get an error like mkdir: cannot create directory 'maze/twisty': No such file or directory.

The -p option is a convenience that automates this step-by-step creation of parent directories.

Do you want to try creating a nested directory structure without using -p to see how it works?

0 Comments

no data
Be the first to share your comment!