Loop to create subdirectories in multiple directories
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to create subdirectories into each of directories below. I used the following loop:
#! bash
/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir
done
but it creates one subdirectory at the same level of directories:
$ ls
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir
I want to get them in this way
$ ls /m3z
/log /lib /txt
$ ls /m3t
/log /lib /txt
.
.
.
$ ls /n dir
/log /lib /txt
Help?
bash loop-device mkdir
add a comment |Â
up vote
0
down vote
favorite
I want to create subdirectories into each of directories below. I used the following loop:
#! bash
/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir
done
but it creates one subdirectory at the same level of directories:
$ ls
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir
I want to get them in this way
$ ls /m3z
/log /lib /txt
$ ls /m3t
/log /lib /txt
.
.
.
$ ls /n dir
/log /lib /txt
Help?
bash loop-device mkdir
1
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to create subdirectories into each of directories below. I used the following loop:
#! bash
/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir
done
but it creates one subdirectory at the same level of directories:
$ ls
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir
I want to get them in this way
$ ls /m3z
/log /lib /txt
$ ls /m3t
/log /lib /txt
.
.
.
$ ls /n dir
/log /lib /txt
Help?
bash loop-device mkdir
I want to create subdirectories into each of directories below. I used the following loop:
#! bash
/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir
done
but it creates one subdirectory at the same level of directories:
$ ls
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir
I want to get them in this way
$ ls /m3z
/log /lib /txt
$ ls /m3t
/log /lib /txt
.
.
.
$ ls /n dir
/log /lib /txt
Help?
bash loop-device mkdir
bash loop-device mkdir
edited Aug 13 at 19:48
slmâ¦
238k65492662
238k65492662
asked Aug 13 at 14:39
Djegdjiga AMAZOUZ
6
6
1
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55
add a comment |Â
1
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55
1
1
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
Assuming the m3*
directories exist,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done
or, with brace expansion on the list of directories,
mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt
or even,
mkdir m3z,t,t2,g,g2,g3/log,lib,txt
or, without the brace expansion,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over are not already existing.
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over already exist and all match the pattern m3*/
,
for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
The main thing is to specify that you'd like to create the directories as subdirectories of $dir
, the directory name that you currently process in your loop.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Assuming the m3*
directories exist,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done
or, with brace expansion on the list of directories,
mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt
or even,
mkdir m3z,t,t2,g,g2,g3/log,lib,txt
or, without the brace expansion,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over are not already existing.
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over already exist and all match the pattern m3*/
,
for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
The main thing is to specify that you'd like to create the directories as subdirectories of $dir
, the directory name that you currently process in your loop.
add a comment |Â
up vote
5
down vote
Assuming the m3*
directories exist,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done
or, with brace expansion on the list of directories,
mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt
or even,
mkdir m3z,t,t2,g,g2,g3/log,lib,txt
or, without the brace expansion,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over are not already existing.
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over already exist and all match the pattern m3*/
,
for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
The main thing is to specify that you'd like to create the directories as subdirectories of $dir
, the directory name that you currently process in your loop.
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Assuming the m3*
directories exist,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done
or, with brace expansion on the list of directories,
mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt
or even,
mkdir m3z,t,t2,g,g2,g3/log,lib,txt
or, without the brace expansion,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over are not already existing.
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over already exist and all match the pattern m3*/
,
for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
The main thing is to specify that you'd like to create the directories as subdirectories of $dir
, the directory name that you currently process in your loop.
Assuming the m3*
directories exist,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done
or, with brace expansion on the list of directories,
mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt
or even,
mkdir m3z,t,t2,g,g2,g3/log,lib,txt
or, without the brace expansion,
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over are not already existing.
for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done
or, if the directories that you loop over already exist and all match the pattern m3*/
,
for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done
The main thing is to specify that you'd like to create the directories as subdirectories of $dir
, the directory name that you currently process in your loop.
edited Aug 13 at 14:51
answered Aug 13 at 14:45
Kusalananda
106k14209327
106k14209327
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462315%2floop-to-create-subdirectories-in-multiple-directories%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Possible duplicate of Issue with Bash Script creating Directories from Arrays
â kemotep
Aug 13 at 15:55