進度 : 鳥哥的 Linux 私房菜 -- 第六章、Linux 檔案與目錄管理
6.3.5 修改檔案時間或建置新檔: touch
查看 touch 用法
test@test:~$ touch --help
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: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/touch>
or available locally via: info '(coreutils) touch invocation'
# 測試修改時間的變化
test@test:~$ touch test.txt
test@test:~$ stat test.txt
File: test.txt
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 262158 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ test) Gid: ( 1000/ test)
Access: 2020-10-08 01:02:29.734259550 +0000
Modify: 2020-10-08 01:02:29.734259550 +0000
Change: 2020-10-08 01:02:29.738259559 +0000
test@test:~$ echo 'test' > test.txt
test@test:~$ stat test.txt
File: test.txt
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 262158 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ test) Gid: ( 1000/ test)
Access: 2020-10-08 01:02:29.734259550 +0000
Modify: 2020-10-08 01:05:33.402647488 +0000
Change: 2020-10-08 01:05:33.402647488 +0000
Birth: -
# 測試修改時間
test@test:~$ touch -d "2020-01-01" test.txt
test@test:~$ stat test.txt
File: test.txt
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 262158 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ test) Gid: ( 1000/ test)
Access: 2020-01-01 00:00:00.000000000 +0000
Modify: 2020-01-01 00:00:00.000000000 +0000
Change: 2020-10-08 01:27:21.710675139 +0000
Birth: -
鳥哥提到重要概念 :
複製一個檔案時,複製所有的屬性,但也沒有辦法複製 ctime 這個屬性的
我們平時看的檔案屬性中,比較重要的還是屬於那個 mtime 啊