Ubuntu – How to create folders in folders in terminal

18.04command linedirectorymusic

I have a folder named music where inside there is all of the artist folders. Is there a way to create these folders: 1. Albums, 2. EP, 3. Singles, 4. Live in all the artist folders with a command?

Best Answer

Sure, execute this in the music folder where the artist folders are:

for artist in */; do
   for folder in "1. Albums" "2. EP" "3. Singles" "4. Live"; do
      mkdir "$artist/$folder"

You can execute this on your CLI, or you can make it a shell script by adding #!/bin/sh as the first line and saving it in a file. Don't forget to make the file executable.

As for what it does: it iterates over all directories (*/) within the current directory, then for each of these directories, iterates over the desired subfolder (the second for), and then makes the desired (relative) subfolder.