Sample Header Ad - 728x90

How do I create a directory in all subdirectories?

42 votes
10 answers
57668 views
Suppose I have a directory structure like this:
$ [~/practice] ls
a/ b/ c/ d/
Now I want to create a directory tmp1 in all sub directories of practice and I do this:
$ [~/practice] mkdir */tmp1
mkdir: cannot create directory `*/tmp1': No such file or directory
Then I try the -p switch and I endup with a directory named * with a sub directory tmp1
$ [~/practice] mkdir -p */tmp1

$ [~/practice] ls
*/ a/ b/ c/ d/
I know the use of -p switch is to create multiple nonexistent directories. I just thought it might help. How do I create tmp1 in all subdirectories at once? If this can be done, how do I extend it to create \tmp1, \tmp2, \tmp3 in \a, \b and \c at once? **Edit:** I missed mentioning that the directories don't have to be simple and in order, like a, b, c etc., and the directory to be created is not necessarily like tmp1, tmp2.
$ [~/practice] ls
dog/ cat/ rat/
In them, I would like to have something like
$ [~/practice] ls *
dog:
red/ blue/

cat:
red/ blue/

rat:
red/ blue/
Asked by Animesh D (2017 rep)
Jan 20, 2013, 03:08 PM
Last activity: Jun 23, 2025, 02:35 PM