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.

  • Hey, just revisiting some questions. Would you mind accepting an answer so other users will know the issue is solved? Cheers – I_GNU_it_all_along Nov 11 '16 at 16:08
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_

  • ... Except when you happen to also have files with named that begin with CT_. :) – Satō Katsura Sep 15 '16 at 13:30
  • Yes, except for in those instances. – I_GNU_it_all_along Sep 15 '16 at 13:31
  • ... Which is why you should enclose the inner statement in if [ -d "$D" ]; then ... fi. – Satō Katsura Sep 15 '16 at 13:33
  • Stephen, this worked perfectly for me. Thank you! – Adrienne Payne Sep 15 '16 at 13:36
  • Or change the loop to CT_*/. which will only match directories... but may follow symlinks :-) – Stephen Harris Sep 15 '16 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.