LoginSignup
1
2

More than 3 years have passed since last update.

bashで連番のディレクトリを作成するワンライナー

Posted at

dir001, dir002, ..., dir010 のような感じにまとめて生成したい。

$ for i in `seq -f %03g 1 10`; do mkdir dir${i}; done

結果

$ ls
dir001  dir002  dir003  dir004  dir005  dir006  dir007  dir008  dir009  dir010

補足

seq コマンドで数字の列を出力できる。連番の生成に便利。

seq [-w] [-f format] [{最初の数}] {最後の数}

-f で形式を指定できる。

$ seq -f %03g 8 11
008
009
010
011

-w で自動で最大幅の桁数に合わせて出力してくれる。


$ seq -w 99 101
099
100
101
$ seq -w 9 11
09
10
11

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2