I found this super useful, so I'm reposting directly from Matt Butcher's site:
Often times, I want to create a full directory structure, and I'd like to do it with just one call to mkdir. That is, I want to create a root directory and multiple subdirectories all at once. Here's how to do this.
mkdir -p myProject/{src,doc,tools,db}
The above creates the top-level directory myProject
, along with all of the subdirectories (myProject/src
, myProject/doc
, etc.). How does it work? There are two things of note about the command above:
- The
-p
flag: This tellsmkdir
to create any leading directories that do not already exist. Effectively, it makes sure thatmyProject
gets created before creatingmyProject/src
.