Home > OS >  Terminal: How to MKDIR multiple directories with different names and auto increment
Terminal: How to MKDIR multiple directories with different names and auto increment

Time:01-29

I need to create multiple directories with mkdir in Terminal with auto-increment: mkdir "apples" "bananas" "oranges" ... etc. Resulting folders should have auto increment at the beginning of each folder: 1 apples, 2 bananas, 3 oranges.

CodePudding user response:

One way would be to make a loop:

#!/bin/bash

fruits=(apples bananas oranges)
i=1

for fruit in "${fruits[@]}"
do
    mkdir "$i $fruit"
    ((   i ))
done
  •  Tags:  
  • Related