Sometime it’s necessary for you to create multiple folders or files. This is normally the case for me when I’m working with the clusters at my work place. Fortunately, In Linux this is easy.
Using the “for loop”, one could easily put together a one-liner to see results. See sample below.
The initial “ls” shows that the directory is empty.
[root@abubu test]# ls -l
total 0
Now, make the magic happens. Run “for ((i=1;i<=10;i++)); do mkdir ./folder-$i; done”
[root@abubu test]# for ((i=1;i<=10;i++)); do mkdir ./folder-$i; done
Now, “ls” will give you 10 folders.
[root@abubu test]# ls -l
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-1
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-10
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-2
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-3
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-4
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-5
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-6
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-7
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-8
drwxr-xr-x 2 root root 4096 Jun 30 15:49 folder-9
total 40
[root@abubu test]#
This is just one way to do this. Please feel free to comment if you know a better way.
Author comments are in a darker gray color for you to easily identify the posts author in the comments
For the bash -
for i in {1..10}; do mkdir folder-$i;done
Bingo and cheers!
Thanks dude…
On my side, here’s what i will do:
1. Use -p option to avoid being bugged with error directory exists, and ‘seq’ command to allow flexible numbering, (i.e: 2,4,6,8 or 1,3,5,7, or any number stepping):
# for i in `seq 1 100`; do mkdir -p “folder-$i”; done
2. for simple few and drilled in directory
# mkdir -p folder-{1,2,3}
# mkdir -p folder-{7,19, 30)