1

I have a problem, I have a catalog /home/robert in which there are subdirectories: Dog, Cat, Bird, Horse

I want to create a Test and Test1 (automatically) in each of these directories to get:

/home/robert/Dog/Test
/home/robert/Dog/Test1

/home/robert/Cat/Test
/home/robert/Cat/Test1

/home/robert/Bird/Test
/home/robert/Bird/Test1

/home/robert/Horse/Test
/home/robert/Horse/Test1

Is this possible to do, for example, one command with regular expressions, or even better in a text file, I enter:

Test
Test1

And somehow I take the name "Test" and "Test1" and I'm going to the command that will create such a structure of catalogs?

I tried:

  • mkdir /home/robert/*/Test
  • mkdir /home/robert/{*}/Test
  • mkdir /home/robert/[*]/Test

Unfortunately, this does not work

Jorengarenar
  • 2,705
  • 5
  • 23
  • 60
  • You could try something like `find /home/robert/* -type d -maxdepth 0 -print0 | xargs -0 -iDIR mkdir -p DIR/Test DIR/Test1` – larsks Sep 09 '21 at 13:29

2 Answers2

1

Thank you ! What you wrote above let me look more precisely on the internet. Thanks to this I wrote a script that solves my problem completely. (The above catalogs "Cat, Dog etc. I only gave as an example), I really wanted to achieve the following solution:

    #!/bin/bash
    mkdir -- {1..300}
      for dir in*; do
      mkdir -- "$dir"/{documents,desktop,email};
    done

Before performing the script I had:

$ tree my_office_users/
my_office_users/
└── script

And after run script, I have 1 to 300 folders and in each of them catalogs: desktop and documents and email.

And that was it!

$ tree my_office_users
my_office_users/
├── 1
│   ├── desktop
│   ├── documents
│   └── email
├── 10
│   ├── desktop
│   ├── documents
│   └── email
├── 100
│   ├── desktop
│   ├── documents
│   └── email
├── 101
│   ├── desktop
│   ├── documents
│   └── email
 .
 .
 .
├── 99
│   ├── desktop
│   ├── documents
│   └── email
└── script
0

This meets your criteria but I'm not sure it's what you wanted.

for dir in deleteme/*/;do mkdir -- "$dir"/{Test,Test1}; done

where deleteme in your case would be /home/robert

If it has to be only a mkdir command you can do this but it doesn't scale:

mkdir -p deleteme/{Dog/{Test1,Test2},Cat/{Test1,Test2},Bird/{Test1,Test2},Horse/{Test1,Test2}}
kenlukas
  • 3,616
  • 9
  • 25
  • 36