【Linux学習】Linuxの基本コマンド(1)~タッチコマンドの詳細解説

【Linux学習】Linuxの必須コマンド(1) – touchコマンドの詳細解説

1.コマンドの詳細説明

touch コマンドは主に通常のファイルを作成するために使用されます。使用法は touch test.txt です。ファイルが存在する場合は、現在のファイル時刻を変更することを意味します。共通パラメータの詳細は次のとおりです:

用法:touch [选项] 文件	将每个文件的访问时间和修改时间改为当前时间;
						不存在的文件将会被创建为空文件,除非使用-c 或-h 选项;
						如果文件名为"-"则特殊处理,更改与标准输出相关的文件的访问时间;
						长选项必须使用的参数对于短选项时也是必需使用的;
-a 						只更改访问时间;
-c, --no-create 		不创建任何文件;
-d, --date=字符串 		使用指定字符串表示时间而非当前时间;
-f						 (忽略)-h, --no-dereference 	会影响符号链接本身,而非符号链接所指示的目的地;
						(当系统支持更改符号链接的所有者时,此选项才有用)-m 						只更改修改时间;
-r, --reference=文件 	使用指定文件的时间属性而非当前时间;
-t STAMP 				使用[[CC]YY]MMDDhhmm[.ss] 格式的时间而非当前时间;
	--time=WORD 		使用 WORD 指定的时间:access、atime、use 都等于-a;
						选项的效果,而 modify、mtime 等于-m 选项的效果;
	--help 				显示此帮助信息并退出;
	--version 			显示版本信息并退出。
请注意,-d 和-t 选项可接受不同的时间/日期格式

2. コマンド例

新しいファイルを作成するか、フォルダーの下に新しいファイルを作成します

[root@nie linux]# ll
总用量 12
drwxr-xr-x. 2 root root 20 6月   1 13:36 word
[root@nie linux]# touch touch.txt
[root@nie linux]# ll
总用量 12
-rw-r--r--. 1 root root  0 6月  16 12:37 touch.txt
drwxr-xr-x. 2 root root 20 6月   1 13:36 word
[root@nie linux]# ll aa/
总用量 4
-rw-r--r--. 1 777 root 22 6月   1 13:00 linux.txt
[root@nie linux]# touch aa/touch.txt
[root@nie linux]# ll aa/
总用量 4
-rw-r--r--. 1  777 root 22 6月   1 13:00 linux.txt
-rw-r--r--. 1 root root  0 6月  16 12:38 touch.txt

ファイルのアクセス(アクセス)時刻を変更、ファイルの変更(変更)時刻を変更

[root@nie linux]# stat aa/linux.txt 
  文件:aa/linux.txt
  大小:22        	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:3400403     硬链接:1
权限:(0644/-rw-r--r--)  Uid:(  777/ UNKNOWN)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2023-06-01 13:35:02.304561000 +0800
最近更改:2023-06-01 13:00:25.626698812 +0800
最近改动:2023-06-01 13:03:32.400686418 +0800
创建时间:-
[root@nie linux]# touch -a aa/linux.txt 
[root@nie linux]# touch -m aa/linux.txt 
[root@nie linux]# stat aa/linux.txt 
  文件:aa/linux.txt
  大小:22        	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:3400403     硬链接:1
权限:(0644/-rw-r--r--)  Uid:(  777/ UNKNOWN)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2023-06-16 12:44:14.090956546 +0800
最近更改:2023-06-16 13:17:20.507824723 +0800
最近改动:2023-06-16 13:17:20.507824723 +0800
创建时间:-

ファイルアクセスを変更する時刻と変更時刻を指定する

[root@nie linux]# stat aa/touch.txt 
  文件:aa/touch.txt
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:35421707    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2023-06-16 12:38:12.999980508 +0800
最近更改:2023-06-16 12:38:12.999980508 +0800
最近改动:2023-06-16 12:38:12.999980508 +0800
创建时间:-
[root@nie linux]# touch -at 202206161327.30 aa/touch.txt 
[root@nie linux]# touch -mt 202206161327.30 aa/touch.txt 
[root@nie linux]# stat aa/touch.txt 
  文件:aa/touch.txt
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:35421707    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2022-06-16 13:27:30.000000000 +0800
最近更改:2022-06-16 13:27:30.000000000 +0800
最近改动:2023-06-16 13:28:26.138780551 +0800
创建时间:-
[root@nie linux]# touch -t 202106161327.30 aa/touch.txt 
[root@nie linux]# stat aa/touch.txt 
  文件:aa/touch.txt
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:35421707    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2021-06-16 13:27:30.000000000 +0800
最近更改:2021-06-16 13:27:30.000000000 +0800
最近改动:2023-06-16 13:30:49.678771025 +0800
创建时间:-

[root@nie linux]# stat touch.txt 
  文件:touch.txt
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:3400402     硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2023-06-16 12:37:39.765982714 +0800
最近更改:2023-06-16 12:37:39.765982714 +0800
最近改动:2023-06-16 12:37:39.765982714 +0800
创建时间:-
[root@nie linux]# touch -d 20010101 01:01:01 touch.txt 
[root@nie linux]# stat touch.txt 
  文件:touch.txt
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:3400402     硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2001-01-01 00:00:00.000000000 +0800
最近更改:2001-01-01 00:00:00.000000000 +0800
最近改动:2023-06-16 16:19:48.872687727 +0800
创建时间:-

説明する

stat コマンドは、ファイルのステータス情報を表示するために使用されます。
stat コマンドで表示できる情報は次のとおりです。
File: ファイル名を表示
Size: ファイル サイズを表示
Blocks: ファイルで使用されているデータ ブロックの総数
IO Block: IO ブロック サイズ
ファイル タイプ (通常のファイル): ファイルtype (通常ファイル)
Device: デバイス番号
Inode: Inode 番号
Hard links (Links): リンク数
Permission (Access): ファイル権限
Gid、Uid: ファイル所有権の Gid と Uid
Access time (アクセス時間) ): 時刻を示すファイルに最後にアクセスしたとき (アクセスのみで、変更されていない)
変更時刻:
ファイルを最後に変更した時刻を示します。 変更時刻: ファイルの属性を最後に変更した時刻を示します。権限、サイズ、属性などを含みます。 .
作成時刻(誕生時刻):ファイルの作成時刻、crtimeですが、調べたところLinuxではこの属性は廃止されており、現在のステータス表示結果は -

おすすめ

転載: blog.csdn.net/weixin_43757336/article/details/131244544