Macで任意のサイズのファイルを作成するコマンドをメモしておきます。
mkfileコマンドを使う
mkfileコマンドを使えばOKです。使い方は以下のとおりです。
mkfileコマンドの注意点
以下のように、1Byteのファイルを作成しようと思って、bオプションを使うと、1Byteではなく、512Byteのファイルが作成されてしまいました。
mkfileのマニュアルを見てみると、b (512)と書かれているので仕様通りのようです。
mkfile creates one or more files that are suitable for use as NFS-mounted swap areas.
The sticky bit is set, and the file is padded with zeroes by default. Non-root users
must set the sticky bit using chmod(1). The default size unit is bytes, but the follow-
ing suffixes may be used to multiply by the given factor: b (512), k (1024), m
(1048576), and g (1073741824).
以下の記事にも書かれていましたが、どうやらbはバイト数ではなくブロック数のようです。間違えないように気をつけましょう。
まとめ
Macで任意のサイズのファイルを作成するときは、mkfileを使いましょう。