I just used mkdir myDir{1,2,3} to create 3 directories called myDir1, myDir2 and myDir3 in the same root directory. Now I'm trying to create 5 subdirectories in each by using

mkdir ~/myDir*/subDir{1,2,3,4,5}

but it's giving me a file already exists message. When I do an ls on the root directory or check in each of the myDir directories, nothing is in them. I've also tried the variation mkdir /myDir*/subDir{1,2,3,4,5} while in the root directory just in case with the same result.


Thanks.

Recommended Answers

All 5 Replies

Hey there,

Just use the -p option to make dir and it should quit complaining about the directory already existing and do what you want. Also, if you don't need to make those dirs under multiple subdirs, you can remove the * character; that may cause it to give you a "no such file or directory" error.

Best wishes,

Mike

Thanks I got it working with

mkdir -p ~/myDir{1,2,3}/subDir{1,2,3,4,5}

now I'm trying to figure out the last step, making files called myFile1,2,3,4 go in each of the subDir's with just one touch command. I know the beg of it...


touch myFile{1,2,3,4,5}

You got it :)

Just add that to the end and you're set!

, Mike

$ touch x{1,2,3}/y{1,2,3,4,5}/myfile{1,2,3,4,5}

$ ls -R x{1,2,3}
x1:
y1 y2 y3 y4 y5

x1/y1:
myfile1 myfile2 myfile3 myfile4 myfile5

x1/y2:
myfile1 myfile2 myfile3 myfile4 myfile5

x1/y3:
myfile1 myfile2 myfile3 myfile4 myfile5

x1/y4:
myfile1 myfile2 myfile3 myfile4 myfile5

x1/y5:
myfile1 myfile2 myfile3 myfile4 myfile5

x2:
y1 y2 y3 y4 y5

x2/y1:
myfile1 myfile2 myfile3 myfile4 myfile5

x2/y2:
myfile1 myfile2 myfile3 myfile4 myfile5

x2/y3:
myfile1 myfile2 myfile3 myfile4 myfile5

x2/y4:
myfile1 myfile2 myfile3 myfile4 myfile5

x2/y5:
myfile1 myfile2 myfile3 myfile4 myfile5

x3:
y1 y2 y3 y4 y5

x3/y1:
myfile1 myfile2 myfile3 myfile4 myfile5

x3/y2:
myfile1 myfile2 myfile3 myfile4 myfile5

x3/y3:
myfile1 myfile2 myfile3 myfile4 myfile5

x3/y4:
myfile1 myfile2 myfile3 myfile4 myfile5

x3/y5:
myfile1 myfile2 myfile3 myfile4 myfile5

Wow thanks!

My god, it's full of stars....


:)

:) Happy to help

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.