ファイル日付の変更方法コマンドを確認していたので、備忘録で記載します。
せっかくなので OS を変えて(RHEL、Mac、AIX) 確認してみました。
環境1:[RHEL 7.8]
・OS確認とファイル作成
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.8 (Maipo)
# touch test
# ls -l test
-rw-r--r--. 1 root root 0 Sep 4 15:44 test
・-t オプションの使用
# touch -t 2001010000 test
# ls -l test
-rw-r--r--. 1 root root 0 Jan 1 2020 test
-> ファイル日付の変更を確認。
--date オプションの使用
# touch --date="2019/2/20" test
# ls -l test
-rw-r--r--. 1 root root 0 Feb 20 2019 test
-> ファイル日付の変更を確認。
(参考) RHEL 7.8 の touch コマンドの help
# touch --h
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
A FILE argument that does not exist is created empty, unless -c or -h
is supplied.
A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.
Mandatory arguments to long options are mandatory for short options too.
-a change only the access time
-c, --no-create do not create any files
-d, --date=STRING parse STRING and use it instead of current time
-f (ignored)
-h, --no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
timestamps of a symlink)
-m change only the modification time
-r, --reference=FILE use this file's times instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
--time=WORD change the specified time:
WORD is access, atime, or use: equivalent to -a
WORD is modify or mtime: equivalent to -m
--help display this help and exit
--version output version information and exit
Note that the -d and -t options accept different time-date formats.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'touch invocation'
環境2:[Mac]
・OS確認とファイル作成
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G103
$ touch test
$ ls -l test
-rw-r--r-- 1 user staff 0 Sep 4 15:40 test
・ -t オプションの使用
$ touch -t 2001010000 test
$ ls -l test
-rw-r--r-- 1 user staff 0 Jan 1 2020 test
-> ファイル日付の変更を確認。
・ --date オプションの使用
$ touch --date="2020/3/20" test
touch: illegal option -- -
usage:
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
$ ls -l test
-rw-r--r-- 1 user staff 0 Jan 1 2020 test
--date オプションは使用できない...
環境3:[AIX 7.2]
・OS確認とファイル作成
# oslevel -s
7200-03-02-1846
# touch test
# ls -l test
-rw-r--r-- 1 root system 0 Sep 4 14:55 test
・-t オプションの使用
# touch -t 2001010000 test
# ls -l test
-rw-r--r-- 1 root system 0 Jan 1 2020 test
#
-> ファイル日付の変更を確認。
・--date オプションが打てるかどうか。
# touch --date="2020/3/20" test
touch: illegal option -- -
usage: touch [-amcf] [MMDDhhmm[YY]] [-t [[CC]YY]MMDDhhmm[.SS]] [-r ref_file] file ...
--date オプションは使用できない...
まとめ
・Mac と AIX touch コマンドの-t オプションでファイル日付の変更が可能でした。
・RHEL は touch コマンドの -t オプション、--date オプションでファイル日付の変更が可能でした。
以上です。