Home > Software engineering >  How do I create the same directory in every subdirectories in bash?
How do I create the same directory in every subdirectories in bash?

Time:03-01

I've been trying to create the directory "a" inside all the subdirectories of "example".

What I tried is the following:

mkdir example/*/a

But it doesn't take the '*' as a wildcard, returning mkdir: can not create «example/*/a» directory: It doesn't exist file or directory

Note that I have too much subdirectories in example, so I can't do it by creating a list.

I don't want to do it with for loops, because they are not fast enough. Probably, there is no way to avoid a for loop, in that case, please tell me :).

Thank you.

CodePudding user response:

Probably, there is no way to avoid a for loop

You can use find:

find example -type d -not -name a -exec mkdir -p {}/a \;

CodePudding user response:

Just:

for i in example/*/; do
    mkdir "$i"/a
done

CodePudding user response:

for d in */; do mkdir "${d}a"; done
  • Related