Easily create lots of new folders

Today's Best Tech Deals

Picked by Macworld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

Have you ever had to create a large series of folders, perhaps for a new project, new client, or just as part of organizing your massively large and massively disorganized hard drive? In the Finder, it’s trivial to create a new folder—just press Shift-Command-N. But if you’ve got 10 or 20 or 30 folders to create, the process can get tedious—create the folder, rename it, create the next, rename it, repeat until done. Ugh. Using Terminal, however, you can greatly simplify this task, as you can easily combine the ‘create’ and ‘rename’ steps into one action.

In Terminal, you use the command mkdir to create new directories (folders). For instance, mkdir “My Folder” will create a folder named My Folder in the current directory. But mkdir is actually more powerful than that, as it will accept multiple new folder names on the input line. For instance, consider this command:

mkdir "My Folder" "My Other Folder" "Not That Folder"

The above will create three new folders with the ever-so-useful names of My Folder, My Other Folder, and Not That Folder. Note the quote marks around each name—you’ll need those if your folder names contain spaces. Alternatively, you can put a backslash before each space and skip the quotes, but I find it easier (and more visually obvious) to use the quotes. Unless you specify the full path to each folder, mkdir will create them in the current directory—so remember to use cd /path/to/destination before creating your new folders.

So what if you have a lot of folders to create? Start by making a text file containing the name of each folder to be created—one entry per line, and any folder name with spaces must be enclosed in quotes (or use backslashes, as explained above). Once you have this file created, place it in the folder where you’d like all the new folders to go, then cd to that same folder in Terminal. Then type this command (assuming you’ve named your file dirlist.txt ):

cat dirlist.txt | xargs mkdir

Each entry in the file will be created as a folder in the current directory. (For the Unix purists, you can also use <dirlist xargs mkdir instead, but I find the cat version easier to comprehend.)

Finally, what if you’d like to create a selection of folders, all with the same base but a varying suffix? For example, Project A, Project B, Project C, etc. Try this command:

mkdir "Project "{A,B,C,D,E,F}

You’re not restricted to single letters, of course—anything you want can go within the curly brackets. Just remember that if you want spaces in the suffixes, you’ll need to enclose them in quotes, too:

mkdir "Project "{"New Home","Vacation","To Do"}

And yes, I know there are a bunch of ways to do this stuff using GUI tools—including Automator, among others. However, it’s Geeky Friday, and none of those GUI tools will help you much if you’re trying to do this work over a remote connection.

Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our affiliate link policy for more details.
Shop Tech Products at Amazon