Loose-Info.com
Last Update 2014/03/11
TOP - Unix系OS - FreeBSD - touch(1)

ファイルのアクセス時刻と修正時刻を変更します。

touch オプション1 ファイルパス1 オプション1(任意) -a アクセス時刻を変更 -c 変更の対象となるファイル -m 修正時刻を変更 -r ファイルパス2 アクセス時刻と修正時刻を(ファイルパス2)の時刻に変更 -t 値1 アクセス時刻と修正時刻を(値1)で指定した時刻へ変更 [[CC]YY]MMDDhhmm.[SS]で指定 ファイルパス1 検索の対象となるファイル

※ オプションなどは個人的に重要と考えられるものを記述しており、記載の無いものは、manページや関連書籍などを参照願います。
※ 実行例の記述は、不要と考えられる部分の削除などの修正を行ったものを掲載しています。
※ 実行例の実行環境はFreeBSD 9.1です。

(例)オプション無し
実行結果
※statの出力形式は改行を挿入し加工しているため、実際と異なります $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 2 23:48:35 2014" "Feb 2 23:48:35 2014" "Feb 2 23:48:35 2014" "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ touch test.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 2 23:50:00 2014" ←変更(ファイルの最終アクセス時刻) "Feb 2 23:50:00 2014" ←変更(変更時刻) "Feb 2 23:50:00 2014" ←変更(inodeの最終アクセス時刻) "Feb 2 23:48:35 2014" 32768 8 0 test.txt

(例) -a
実行結果
※statの出力形式は改行を挿入し加工しているため、実際と異なります $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 2 23:50:00 2014" "Feb 2 23:50:00 2014" "Feb 2 23:50:00 2014" "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ touch -a test.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 00:41:52 2014" ←変更(ファイルの最終アクセス時刻) "Feb 2 23:50:00 2014" "Feb 3 00:41:52 2014" ←変更(inodeの最終アクセス時刻) "Feb 2 23:48:35 2014" 32768 8 0 test.txt

(例) -c
実行結果
$ ls -l total 4 -rw-r--r-- 1 ******* ******* 5 Feb 2 23:50 test.txt $ touch test2.txt $ ls -l total 4 -rw-r--r-- 1 ******* ******* 5 Feb 2 23:50 test.txt -rw-r--r-- 1 ******* ******* 0 Feb 3 01:08 test2.txt $ touch -c test3.txt ←新規には作成しない $ ls -l total 4 -rw-r--r-- 1 ******* ******* 5 Feb 2 23:50 test.txt -rw-r--r-- 1 ******* ******* 0 Feb 3 01:08 test2.txt

(例) -m
実行結果
※statの出力形式は改行を挿入し加工しているため、実際と異なります $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 00:41:52 2014" "Feb 2 23:50:00 2014" "Feb 3 00:41:52 2014" "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ touch -m test.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 00:41:52 2014" "Feb 3 02:35:18 2014" ←変更(変更時刻) "Feb 3 02:35:18 2014" ←変更(inodeの最終アクセス時刻) "Feb 2 23:48:35 2014" 32768 8 0 test.txt

(例) -r
実行結果
※statの出力形式は改行を挿入し加工しているため、実際と異なります $ ls -l total 4 -rw-r--r-- 1 ******* ******* 5 Feb 3 02:35 test.txt -rw-r--r-- 1 ******* ******* 0 Feb 3 01:08 test2.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 00:41:52 2014" "Feb 3 02:35:18 2014" "Feb 3 02:35:18 2014" "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ stat test2.txt 100 7958282 -rw-r--r-- 1 ******* ******* 0 0 "Feb 3 01:08:00 2014" "Feb 3 01:08:00 2014" "Feb 3 01:08:00 2014" "Feb 3 01:08:00 2014" 32768 0 0 test2.txt $ touch -r test2.txt test.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 01:08:00 2014" ←変更(ファイルの最終アクセス時刻) "Feb 3 01:08:00 2014" ←変更(変更時刻) "Feb 3 02:42:22 2014" ←変更(inodeの最終アクセス時刻)・実行時刻 "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ ls -l total 4 -rw-r--r-- 1 ******* ******* 5 Feb 3 01:08 test.txt -rw-r--r-- 1 ******* ******* 0 Feb 3 01:08 test2.txt

(例) -t
実行結果
※statの出力形式は改行を挿入し加工しているため、実際と異なります $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Feb 3 01:08:00 2014" "Feb 3 01:08:00 2014" "Feb 3 02:42:22 2014" "Feb 2 23:48:35 2014" 32768 8 0 test.txt $ touch -t 201401010000 test.txt $ stat test.txt 100 7958281 -rw-r--r-- 1 ******* ******* 15918631 5 "Jan 1 00:00:00 2014" ←変更(ファイルの最終アクセス時刻) "Jan 1 00:00:00 2014" ←変更(変更時刻) "Feb 3 02:51:19 2014" "Jan 1 00:00:00 2014" ←変更(inodeの生成時刻) 32768 8 0 test.txt