Linux mkdir - How to create multiple directory levels at one time

Linux mkdir question: I'm about to go to work on a new server, and I want to create subdirectories named docs, bin, and lib, and the docs directory has two subdirectories named personal and business. How can I create these directories and subdirectories with one command?

Answer: Use the -p option of the Unix/Linux mkdir command. The answer is shown below:

mkdir -p bin docs/personal docs/business lib

The -p option of the Linux mkdir command tells mkdir to "create parent directories as needed" when it's told to create directories that are multiple levels deep, such as "docs/personal".


Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.