Score:0

Create child directories from parent directory

cn flag
ray

A parent directory has many directories, for example:

cd parent
ls    
ALA_31_C   ALA_31_D   ALA_31_G  ALA_31_L

I want to create the same name directory within each child directory, something like this:

cd  parent
ls
ALA_31_C   ALA_31_D   ALA_31_G  ALA_31_L

cd ALA_31_C
ls
ALA_31_C

Similarly, I need to create it for all remaining directories: ALA_31_D, ALA_31_G and ALA_31_L from the parent directory.

vn flag
Why you want a directory with the same name as its parent? Seems an [XY problem](https://en.wikipedia.org/wiki/XY_problem). Maybe there is a better solution
Score:3
us flag

A simple Bourne shell script will do it:

#!/bin/sh
  
for dir_name in */ ; do
    echo "$dir_name"
    mkdir "$dir_name/$dir_name"
done        

Loop through only the directories (*/), and for each directory, make a child with the same name as the parent (mkdir "$dir_name/$dir_name").

This only works for one level - it is not recursive - which is probably what you want anyway.

For more examples, see How do I loop through only directories in bash?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.