Batch creating a list of folders using the Terminal

Batch creating folders with the terminal is easy and efficient.

Here’s a quick tip for anyone needing to create a large set of folders. This is often required when building the hierarchy of a large web site, or just for organizing the filesystem on your computer.

For example, in Graphic & Web Design we have the end-of-program comprehensive assessment. This is what the list of items required for the assessment looks like:

  • Advertising material
  • Advertising material 2
  • Animation
  • Before and after retouching
  • Book chapter
  • Brochure with complex alignments
  • Catalog
  • Complete stationery set
  • Creative photography
  • Dust jacket
  • Ebook
  • Facebook retail banner
  • Formatting a web page for optimized sharing
  • Infographic
  • Logo collage
  • Lookbook with original photography and illustration
  • Magazine cover with original photography and or illustration
  • Magazine
  • Mockup web site design
  • Newsletter
  • Packaging
  • Photo retouching
  • Poster with full page illustration art
  • Print newsletter
  • Responsive email
  • Web form with complex alignments
  • WordPress front end design CSS
  • Short video (embedded in a web page)
  • Creative/personal web site

That’s a lot of folders to create one-by-one right?

Getting ready for the assessment means going through three years of files and finding which ones fit in which category. The easiest way to do this is to sort through your files and drop them into specific folders as you go.

So here’s the time saver…

If you were given the list of folders, first make sure you put the folder names with multiple words inside quotation marks. Then remove any returns, ie make sure all the folder names are on one single line in your text editor.

Switch to the Finder to create your parent folder. For example, create a folder called “Comprehensive Assessment” on your desktop. Then open up the Terminal.

In the Terminal type “cd ” (note the space after the letter d). Then drag your folder from the finder to the terminal window. This will paste the path to your folder in the terminal. You should see something similar to this:

cd /Users/0123456/Desktop/Comprehensive\ Assessment/

Hit “Enter” to move to that folder in the terminal.

You will be using the mkdir “make directory” command. Paste this block of code in the terminal and hit the return key:

mkdir "Advertising material" "Advertising material 2" Animation "Before and after retouching" "Book chapter" "Brochure with complex alignments" Catalog "Complete stationery set" "Creative photography" "Dust jacket" Ebook "Facebook retail banner" "Formatting a web page for optimized sharing" Infographic "Logo collage" "Lookbook with original photography and illustration" "Magazine cover with original photography and or illustration" Magazine "Mockup web site design" Newsletter Packaging "Photo retouching" "Poster with full page illustration art" "Print newsletter" "Responsive email" "Web form with complex alignments" "Wordpress front end design css" "Short video" "Creative web site"

All your folders will be created.

Create subfolders

You can create subfolders by first moving into one of the subfolders with the cd command followed by the name of the subfolder and then the enter key.

cd Advertising\ material
mkdir redo tweak publish

Using autocomplete to type less

The terminal has an “autocomplete” feature built-in. As you type the name of one of the subfolders (or any path actually), hit the tab key. The rest of the characters in the name of the path/file name will be auto-completed.

If there are multiple files with the same set of first letters in their name, it will autocomplete what it can. You must then manually type the first different letter, then hit tab again to autocomplete the rest of the path.

Perform multiple operations in one command

You can do multiple operations at the same time like switching to another folder and creating subfolders with one command:

Switch to another folder called “animation” with cd (single command):

cd ../animation

Switch to another folder called “animation” with cd and then create three subfolders inside it (four actions in a single command):

cd ../animation && mkdir redo tweak publish

Scroll through your command history

You can hit the up or down arrow keys to scroll through your history of terminal commands to avoid retyping the same things over and over again. Just hit the arrow keys (up or down) to find the right one and hit enter to execute the command.

You’re welcome. 😉

Author: Eric Girouard

Eric Girouard is a photography and design teacher in the Graphic & Web Design department, which he joined in 2001. He holds a BFA in Fine Art specializing in Drawing & Painting from Concordia University. His stock images were distributed worldwide by Corbis. Eric also worked at Trey Ratcliff’s “The Arcanum – Magical Academy of Artistic Mastery” and served as a photo contest judge for Viewbug.com.

Leave a Reply