Home > Enterprise >  How to create a parent directory with multiple subdirectories which has nested subdirectories within
How to create a parent directory with multiple subdirectories which has nested subdirectories within

Time:07-02

I'm new to shell scripting. I'm trying to create a main folder called Analysis. In the Analysis folder I would like four sub-folders named, PhenV1, PhenV2, HypV1, and HypV2. I then want to have each of those four sub-folders have another 2 folders named Genes and Variants and in each of the Genes and Variants folders to have two more folders named CNV and SNV. The directory structure is depicted by the image below. Here is what I've attempted

mkdir -p Analysis/PhenV1/{Genes/{CNV,SNV},Variants/{CNV,SNV},PhenV2/{Genes/{CNV,SNV},Variants/{CNV,SNV},HypV1/{Genes/{CNV,SN},Variants/{CMC,VT},HypV2/{Genes/{CNV,SNV},Variants/{CNV,SNV}}

This code only creates the parent folder Analysis, and subdirectories, PhenV1 and {Genes''m

enter image description here

CodePudding user response:

mkdir -p Analysis/{PhenV1,Phenv2,HypV1,HypV2}/{Genes,Variants}/{CNV,SNV}

Creates:

$ tree
.
└── Analysis
    ├── HypV1
    │   ├── Genes
    │   │   ├── CNV
    │   │   └── SNV
    │   └── Variants
    │       ├── CNV
    │       └── SNV
    ├── HypV2
    │   ├── Genes
    │   │   ├── CNV
    │   │   └── SNV
    │   └── Variants
    │       ├── CNV
    │       └── SNV
    ├── PhenV1
    │   ├── Genes
    │   │   ├── CNV
    │   │   └── SNV
    │   └── Variants
    │       ├── CNV
    │       └── SNV
    └── Phenv2
        ├── Genes
        │   ├── CNV
        │   └── SNV
        └── Variants
            ├── CNV
            └── SNV

29 directories, 0 files

CodePudding user response:

Your brackets are not properly balanced. Try:

Analysis/{PhenV1/{Genes/{CNV,SNV},Variants/{CNV,SNV}},PhenV2/{Genes/{CNV,SNV},Variants/{CNV,SNV}},HypV1/{Genes/{CNV,SN},Variants/{CMC,VT}},HypV2/{Genes/{CNV,SNV},Variants/{CNV,SNV}}}

Which can be simplified a bit:

Analysis/{{PhenV1,PhenV2,HypV2}/{Genes,Variants}/{CNV,SNV},HypV1/{Genes/{CNV,SN},Variants/{CMC,VT}}}
  • Related