Tukubaiオンラインコマンドマニュアル - itouch(1)

itouch(1)

【名前】

itouch : ファイルの初期化を行う

【書式】

Usage   : itouch [-<n>] "<string>" <file1> <file2>...
        : itouch [-<n>] -f <file> <file1> <file2>...
Version : Thu Aug 20 20:30:32 JST 2015
Edition : 1

【説明】

指定ファイルが存在しない、あるいは0バイトならば、<string>あるいは<file>でファイルの中身を初期化します。-<n>で数字を指定すると<n>行分の<string>あるいは<n>回分の<file>で初期化します。初期化するファイルは複数指定できます。ファイルが存在して0バイトで無い場合は何もしません。指定ファイルが"-"のときは、標準入力を期待し、結果を標準出力に出力します。

【例1】

$ cat file
cat: file: No such file or directory  <-- ファイルが存在しないか0バ
                                          イトの場合
$ itouch '000 000 0' file
$ cat file
000 000 0                             <-- 指定文字列で初期化される
$ itouch 'abc abc 0' file             <-- ファイルが存在して0バイト
                                          でない場合
$ cat file
000 000 0

【例2】

$ : > file
$ itouch -3 '000 000 0' file          <-- 3行初期化
$ cat file
000 000 0
000 000 0
000 000 0

【例3】

$ : > file
$ itouch 'a\nb\nc' file               <-- '\n' は改行に置換される
$ cat file
a
b
c

【例4】

$ cat file1
$ cat file1 | itouch '000 0' - > result  <-- 標準入力から0バイト
$ cat result                                 ファイルを読む
000 0
$ cat file2
ABC D
$ cat file2 | itouch '000 0' - > result  <-- 標準入力から中身のある
$ cat result                                 ファイルを読む
ABC D

【例5】

$ : > file
$ echo abc > init       <-- 初期化用のファイルを準備する
$ itouch -f init file   <-- 初期化ファイル init で file を初期化する
$ cat file
abc

【関連項目】

touch (1)

Last modified: 2022-08-13 08:42:33