dz网站恢复数据库怡清源企业网站建设可行性分析
web/
2025/10/7 0:22:58/
文章来源:
dz网站恢复数据库,怡清源企业网站建设可行性分析,网页设计大赛新闻稿,wordpress添加pptLinux系统之touch命令的基本使用 一、touch命令介绍1. touch命令简介2. touch命令作用 二、touch命令帮助1. touch命令的帮助信息2. touch命令的选项解释 三、touch命令的基本使用1. 查看touch工具版本2. 创建空文件3.查看空文件属性4. 修改文件时间戳5. 文件不存在时不创建 四… Linux系统之touch命令的基本使用 一、touch命令介绍1. touch命令简介2. touch命令作用 二、touch命令帮助1. touch命令的帮助信息2. touch命令的选项解释 三、touch命令的基本使用1. 查看touch工具版本2. 创建空文件3.查看空文件属性4. 修改文件时间戳5. 文件不存在时不创建 四、总结 一、touch命令介绍
1. touch命令简介 touch命令用于创建空文件或修改现有文件的时间戳。 2. touch命令作用
touch命令 有两个功能 创建新文件如果你指定一个不存在的文件名作为touch命令的参数它将在当前目录下创建一个新的空文件。这在需要快速创建一些空的文本文件或者配置文件时非常有用。 更新文件的时间戳对于已经存在的文件touch命令会更新该文件的访问时间和修改时间标记为当前系统时间。这并不改变文件的内容只是修改了文件的元数据即文件的“最近访问时间”atime和“最近修改时间”mtime。这对于某些需要基于文件更新时间进行逻辑处理的情况非常有用比如让cron任务认为某个脚本是“新”的以便重新执行。
二、touch命令帮助
1. touch命令的帮助信息 在centos7.6中touch命令是系统默认已安装的可通过touch --help查询帮助信息。 [rootjeven ~]# 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, --dateSTRING parse STRING and use it instead of current time-f (ignored)-h, --no-dereference affect each symbolic link instead of any referencedfile (useful only on systems that can change thetimestamps of a symlink)-m change only the modification time-r, --referenceFILE use this files times instead of current time-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time--timeWORD change the specified time:WORD is access, atime, or use: equivalent to -aWORD is modify or mtime: equivalent to -m--help display this help and exit--version output version information and exitNote 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. touch命令的选项解释 touch命令的选项解释 -a仅修改文件的访问时间atime。
-c如果文件不存在不要创建新文件。
-d设置文件的时间戳为指定时间可以使用各种格式的日期时间值如“2021-12-31 23:59:59”、“next Friday”、“3 hours”等。
-m仅修改文件的修改时间mtime。
-r将目标文件的时间戳与指定文件的时间戳相同。
-t设置文件的访问时间和修改时间为指定时间格式与-d选项相同。
--help在线帮助
--version显示版本信息。三、touch命令的基本使用
1. 查看touch工具版本 查看touch工具版本可以看到在centos7.6中默认安装的版本为 8.22。 [rootjeven ~]# touch --version
touch (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.Written by Paul Rubin, Arnold Robbins, Jim Kingdon,
David MacKenzie, and Randy Smith.
2. 创建空文件 使用touch命令创建空文件 [rootjeven tmp]# touch file01.txt
[rootjeven tmp]# ls
file01.txt3.查看空文件属性 查看touch创建的空文件属性 [rootjeven tmp]# file file01.txt
file01.txt: empty写入文本内容后再次查看文件属性。
[rootjeven tmp]# echo aa file01.txt
[rootjeven tmp]# file file01.txt
file01.txt: ASCII text
4. 修改文件时间戳
查看当前文件的时间戳
[rootjeven tmp]# stat file01.txt File: ‘file01.txt’Size: 3 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 18451793 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-07-10 19:55:25.464098671 0800
Modify: 2023-07-10 19:55:21.487098520 0800
Change: 2023-07-10 19:55:21.487098520 0800Birth: -
要修改文件的访问时间和修改时间为当前时间
touch -t $(date %Y%m%d%H%M.%S) file01.txt 5. 文件不存在时不创建 使用-c选项当文件不存在时则不创建该文件。 [rootjeven tmp]# touch -c aa
[rootjeven tmp]# ls
file01.txt
四、总结
使用touch命令时有几点注意事项需要留意 权限问题你需要有足够权限才能使用touch命令创建或修改文件的时间戳。如果没有相应的权限比如尝试在没有写权限的目录下创建文件命令将会失败并返回错误信息。 仅修改时间戳touch命令主要作用是修改文件的访问和修改时间戳并不会改变文件的实际内容。如果你需要编辑文件内容应该使用如vi、nano或echo等其他命令或工具。 创建新文件当指定的文件名不存在时touch会创建一个新的空文件。如果文件已存在它不会被清空只是时间戳会被更新。 更新时间选项使用-a只更新访问时间atime使用-m只更新修改时间mtime。如果不指定两者都会被更新为当前时间。 时间戳设定使用-t或-d选项可以设定特定的时间戳而不是使用当前时间。确保按照正确的格式输入日期和时间否则命令可能无法正确执行。 引用文件时间戳使用-r选项可以将一个文件的时间戳复制到另一个文件上这在批量调整文件时间时特别有用。 防止创建文件加上-c选项后如果文件已存在touch将只更新其时间戳而不创建新文件。如果文件不存在命令不做任何操作且不返回错误。 环境变量与别名在某些系统或用户的配置中touch命令可能已被别名重定义或受环境变量影响因此了解当前环境的具体行为是很重要的特别是在执行自动化脚本时。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/88182.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!