Score:2

Nested sequence of directories

in flag

I am making nested directories using a command like this:

mkdir -p 1/2/3/4

However, for many nested directories it takes too much time.

If I want to create 100 directories, what should I do?

vanadium avatar
cn flag
You really want to make so many directories? You can always automate using scripts.
Momin Adnan avatar
in flag
Actually I am new to CLI so I just wanted to try out things. How can I automate using scripts?
Score:2
ca flag

You can run:

mkdir -p $(printf "%s" {1..100}/)

where brace expansion is used with / as the optional <SUFFIX> parameter.

Momin Adnan avatar
in flag
Thanks for the help
BeastOfCaerbannog avatar
ca flag
@MominAdnan You're welcome!
BeastOfCaerbannog avatar
ca flag
@MominAdnan (Just a reminder: Click the gray checkmark next to the answer that you think it helped you most, to mark it as the solution. This way other users will also know that this problem has been solved!)
Score:1
kr flag

You could use a for loop:

#!/bin/bash

p=''
for i in {1..100}; do
  p+=$i/
done
mkdir -p "$p"
Momin Adnan avatar
in flag
Thanks, this works
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.