読者です 読者をやめる 読者になる 読者になる

アルファベットや数字の連番でディレクトリを大量に作る

アルファベットや数字の連番でディレクトリを大量に作る時のbashコマンドのメモ

mkdir /tmp/{0..9}
mkdir /tmp/{a..z}

このコマンドで↓こんな感じのディレクトリを一気に作れる。

[root@test tmp]# ls -la
drwxrwxr-x 38 root root 4096 Mar 30 00:00 .
drwxrwxr-x  3 root root 4096 Mar 30 00:00 ..
drwxrwxr-x 38 root root 4096 Mar 30 00:00 0
drwxrwxr-x 38 root root 4096 Mar 30 00:00 1
drwxrwxr-x 38 root root 4096 Mar 30 00:00 2
drwxrwxr-x 38 root root 4096 Mar 30 00:00 3
drwxrwxr-x 38 root root 4096 Mar 30 00:00 4
drwxrwxr-x 38 root root 4096 Mar 30 00:00 5
drwxrwxr-x 38 root root 4096 Mar 30 00:00 6
drwxrwxr-x 38 root root 4096 Mar 30 00:00 7
drwxrwxr-x 38 root root 4096 Mar 30 00:00 8
drwxrwxr-x 38 root root 4096 Mar 30 00:00 9
drwxrwxr-x 38 root root 4096 Mar 30 00:00 a
drwxrwxr-x 38 root root 4096 Mar 30 00:00 b
drwxrwxr-x 38 root root 4096 Mar 30 00:00 c
drwxrwxr-x 38 root root 4096 Mar 30 00:00 d
drwxrwxr-x 38 root root 4096 Mar 30 00:00 e
drwxrwxr-x 38 root root 4096 Mar 30 00:00 f
drwxrwxr-x 38 root root 4096 Mar 30 00:00 g
drwxrwxr-x 38 root root 4096 Mar 30 00:00 h
drwxrwxr-x 38 root root 4096 Mar 30 00:00 i
drwxrwxr-x 38 root root 4096 Mar 30 00:00 j
drwxrwxr-x 38 root root 4096 Mar 30 00:00 k
drwxrwxr-x 38 root root 4096 Mar 30 00:00 l
drwxrwxr-x 38 root root 4096 Mar 30 00:00 m
drwxrwxr-x 38 root root 4096 Mar 30 00:00 n
drwxrwxr-x 38 root root 4096 Mar 30 00:00 o
drwxrwxr-x 38 root root 4096 Mar 30 00:00 p
drwxrwxr-x 38 root root 4096 Mar 30 00:00 q
drwxrwxr-x 38 root root 4096 Mar 30 00:00 r
drwxrwxr-x 38 root root 4096 Mar 30 00:00 s
drwxrwxr-x 38 root root 4096 Mar 30 00:00 t
drwxrwxr-x 38 root root 4096 Mar 30 00:00 u
drwxrwxr-x 38 root root 4096 Mar 30 00:00 v
drwxrwxr-x 38 root root 4096 Mar 30 00:00 w
drwxrwxr-x 38 root root 4096 Mar 30 00:00 x
drwxrwxr-x 38 root root 4096 Mar 30 00:00 y
drwxrwxr-x 38 root root 4096 Mar 30 00:00 z


数字の「0」ディレクトリの下にアルファベットの「a」ディレクトリを作るなどといった複数階層で作るとき
mkdir -p /tmp/{0..9}/{a..z}
mkdir -p /tmp/{0..9}/{0..9}
mkdir -p /tmp/{a..z}/{0..9}
mkdir -p /tmp/{a..z}/{a..z}

こんな感じ