Site icon Asian Efficiency

Creating Multiple Folders from a Text File in Terminal

The Productivity Show

At Thanh’s request, I’m sharing this. Consider it a sneak preview for our upcoming “AE Labs” project.

One of  the ways that we organize ourselves at Asian Efficiency is to have one folder per article or post we write. This is used for storing the article, the mind map, images and anything else relevant. Think of it as a project folder.

Now obviously, efficiency comes from doing things in batches. So, how do you make 40+ folders at the same time?

1. Create a text file with folder names. I simply did this by copying out of our planning spreadsheet, replacing spaces with dashes and adding dates (all easily done in Excel). We then get something that looks like this:

20120601-article1
20120602-article2
20120603-article3
20120604-article4
20120605-article5
20120606-article6
20120607-article7
20120608-article8
20120609-article9
20120610-article10
20120611-article11
20120612-article12
20120613-article13
20120614-article14
20120615-article15
20120616-article16
20120617-article17
20120618-article18
20120619-article19
20120620-article20

Note that the date format of YYYMMDD allows computers to sort dates in ascending or descending orders easily, and completely eliminates any confusion caused by US-or-rest-of-the-world date formats.

2. Save as folders.txt in a temporary directory.

3. Open Terminal (Mac/Unix only). Not sure about Windows PowerShell. Go to the folder where folders.txt is.

4. Type the command:

$ cat folders.txt | xargs mkdir

I am by no means a proficient terminal user or programmer, but let me try to break that down.

$ is the standard prompt for Terminal. You don’t type it, it appears when you first launch Terminal.

cat stands for concatenate. Which means it takes folders.txt and reads it sequentially (line by line) then outputs it.

| is a pipe, which means it takes whatever is to the left of the pipe and outputs it to the command on the right of the pipe.

xargs I have no idea. Wikipedia has a complicated explanation. I’m thinking of it as “compleX ARGumentS“, meaning it takes a long list of something and lets other commands interpret it easier.

mkdir stands for make directory.

5. You’re done!

Exit mobile version