LoginSignup
1
1

More than 5 years have passed since last update.

macOSのターミナルでゼロ埋めの連番ファイルを作る

Last updated at Posted at 2018-02-28

アルゴリズム演習をやっていて、001.phpから014.phpまでの連番ファイルが欲しかったのですが、ググったら「ブレース使え」ってのが出てきました。

bash
$ touch {001..9}.php

なるほど、超いーじゃん、と思いましたが・・・

bash
$ ls
1.php   2.php   3.php   4.php   5.php   6.php   7.php   8.php   9.php

は?
ゼロ埋めできてない。
ブレースはだめだ。

そういえばseqってあったなと思いました。
manしました。
-fってオプションがありました。

bash
$ for i in `seq -f %03g 1 9`; do touch $i.php; done

はい。

bash
$ ls
001.php 002.php 003.php 004.php 005.php 006.php 007.php 008.php 009.php

できました。

以上です。

追記

bash
$ echo $SHELL
/bin/bash
$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
1
1
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
1