0

I have a directory containing several folders with different names, and I need to create a subdirectory in each individual folder.

The path for one of the folders looks like this:

/Volumes/Server1/Craft/2OQ/Dom_Curr/EN/CT_1

There are multiple CT_xyz (CT_1 through CT_124) folders in the EN directory, and I need to put a subdirectory in each CT folder like this:

/Volumes/Server1/Craft/2OQ/Dom_Curr/EN/CT_1/5Misc/Permissions

The 5Misc/Permissions folders need to go in each individual folder.

1
  • Hey, just revisiting some questions. Would you mind accepting an answer so other users will know the issue is solved? Cheers Nov 11, 2016 at 16:08

2 Answers 2

1

Change into the /Volumes/Server1/Craft/2OQ/Dom_Curr/EN directory:

cd /Volumes/Server1/Craft/2OQ/Dom_Curr/EN

Then run the following:

for D in CT_*
do
    mkdir -p ${D}/5Misc/Permissions
done

This will add the subdirectories to every directory in the EN directory that begins with CT_

9
  • ... Except when you happen to also have files with named that begin with CT_. :) Sep 15, 2016 at 13:30
  • Yes, except for in those instances. Sep 15, 2016 at 13:31
  • ... Which is why you should enclose the inner statement in if [ -d "$D" ]; then ... fi. Sep 15, 2016 at 13:33
  • Stephen, this worked perfectly for me. Thank you! Sep 15, 2016 at 13:36
  • Or change the loop to CT_*/. which will only match directories... but may follow symlinks :-) Sep 15, 2016 at 13:36
0

Use the list fuction of bash integrated into the usual mkdir:

mkdir /Volumes/Server1/Craft/2OQ/Dom_Curr/EN/CT{1..124}

Source: https://askubuntu.com/questions/731721/is-there-a-way-to-create-multiple-directories-at-once-with-mkdir

Original author: https://askubuntu.com/users/15811/rinzwind

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .