The mkdir command can create not just a directory but also a complex directory structure if you ask in the right way. The mkdir command can do more than create a single directory. It can create multiple directories at once and can even create an entire directory structure with a single command. The required command will be a tad complex, but not particularly challenging. NOTE: If you try to set up a multi-level directory structure with a command like the one shown below, it won’t work if the initial directories (“this” and “that”) don’t already exist. $ mkdir this/that/the_other mkdir: cannot create directory ‘this/that/the_other’: No such file or directory Add a -p (for “parents”) and the missing directories will be created and your this/that/the_other directory structure will be set up in your current directory as intended. $ mkdir -p this/that/the_other $ ls -l this/that total 4 drwxrwxr-x 2 shs shs 4096 Jul 7 10:01 the_other Creating a more complex directory structure You can also set up a directory structure that has multiple subdirectories at some level. In the following example, four separate directories will be set up within the Documents/personal directory. And, again, given the use of -p, the Documents and Documents/personal directories will first be set up if they don’t already exist. $ mkdir -p ~/Documents/personal/{home,family,finances,stories} $ ls -l Documents/personal total 16 drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 family drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 finances drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 home drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 stories In addition, you can specify a series of subdirectories at multiple levels in the directory tree that you’re setting up. Here’s a very simple example: $ mkdir -p testing/{1,2,3}/{a,b,c} This will set up three subdirectories within a “testing” directory and three subdirectories within each of those subdirectories. If you have the tree command installed, you can view the new structure with a command like this one: $ tree testing testing ├── 1 │ ├── a │ ├── b │ └── c ├── 2 │ ├── a │ ├── b │ └── c └── 3 ├── a ├── b └── c In addition, you can add additional subdirectory levels if you need to. Another option is to use syntax like that shown below to create subdirectories in only one of the new directories. You can do that by adding curly brackets around a portion of the command as shown below so that only the articles directory will be set up with subdirectories. $ mkdir -p tech/{articles/{new,old},images,notes,comments} Again, the tree command will give you a useful view of the directory structure you have just created. $ tree tech tech ├── articles │ ├── new │ └── old ├── comments ├── images └── notes Wrap-up The mkdir command can create complex directory structures and the tree command is perfect for confirming the directory structure you’ve just set up. Keep in mind that you can remove a directory structure with a command like “rm -rf this” if your command didn’t do just what you needed it to do and try again. Related content how-to How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe