2

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?

2
  • You really want to make so many directories? You can always automate using scripts.
    – vanadium
    Jan 24 at 16:41
  • Actually I am new to CLI so I just wanted to try out things. How can I automate using scripts? Jan 24 at 17:28

2 Answers 2

2

You can run:

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

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

2
1

You could use a for loop:

#!/bin/bash

p=''
for i in {1..100}; do
  p+=$i/
done
mkdir -p "$p"
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.