DEV Community

Emanoel Lopes
Emanoel Lopes

Posted on

Creating multiples directories from a file on bash terminal

The problem

A repetitive task to do: create 111 directories with 2 sub directories each one. The structure is:

├── SMD0088
│   ├── files
│   └── tasks
Enter fullscreen mode Exit fullscreen mode

The names are from a spreadsheet column.

The motivation

I need to prepare 6 computer labs for next semester classes. Each professor has a small list of application to install on a right lab.

The Solution

Create an Ansible role to each subject and a playbook for each lab.

The procedure

  1. Copy and paste the spreadsheet column and save as 'd' file.
  2. Navigate to 'playbook/roles' ansible directory and run the command:

$ while read line; do mkdir -p $line/{tasks,files}; done < d

The result

The line 'SMD0088' on "d" turns on to 'SMD0088/files' and 'SMD0088/tasks' directories.

Top comments (1)

Collapse
 
dvoltaire profile image
dvoltaire • Edited

Assuming your base directory is SMD, and you want a 4 digit in your directory name, run this command below.
mkdir -p SMD{0001..111}/{files,tasks}
Samples output from the tree command.

│   └── tasks
├── SMD0087
│   ├── files
│   └── tasks
├── SMD0088
│   ├── files
│   └── tasks
├── SMD0089
│   ├── files
│   └── tasks
├── SMD0090
│   ├── files
│   └── tasks
├── SMD0091
│   ├── files
│   └── tasks
├── SMD0092
│   ├── files
│   └── tasks

Enter fullscreen mode Exit fullscreen mode

To delete those directories, run this command:
rm -r SMD{0001..111}