每天一个Linux命令(4)touch命令
touch命令有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;二是用来创建新的空文件。
(1)用法
用法:touch [选项]... 文件...
(2)功能
1)将每个文件的访问时间和修改时间改为当前时间;
2)不存在的文件将会被创建为空文件,除非使用-c 或-h 选项;
(3)选项参数
1) -f, --force 忽略不存在的文件,从不给出提示
2) -i, --interactive 进行交互式删除
3) -r, -R, --recursive 指示rm将参数中列出的全部目录和子目录均递归地删除
4) -v, --verbose 详细显示进行的步骤
5) --help 显示此帮助信息并退出
6) --version 输出版本信息并退出
7) -a 只更改访问时间
8) -d, --date=字符串 使用指定字符串表示时间替代当前时间
9) -t STAMP 使用[[CC]YY]MMDDhhmm[.ss] 格式的时间替代当前时间
(4)实例:
1)[root@localhost /]# touch /home/sunjimeng/Document/touch_test_file 在指定目下创建文件,如果没有指定,则默认在当前文件夹下(若文件已经存在,则可以看作重新更改文件档案时间)
[root@localhost /]# ls -l /home/sunjimeng/Document
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
[root@localhost /]# touch /home/sunjimeng/Document/touch_test_file
[root@localhost /]# cd home/sunjimeng/Document
[root@localhost Document]# ll
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
-rw-r--r--. root root 5月 : touch_test_file //第一次创建的时间
[root@localhost Document]#
[root@localhost Document]# touch touch_test_file
[root@localhost Document]# ll
总用量 0
drwxrwxr-x. 3 sunjimeng sunjimeng 17 5月 1 03:13 bin
drwxrwxr-x. 3 sunjimeng sunjimeng 18 5月 1 03:21 Father
-rw-r--r--. 1 root root 0 5月 1 18:35 touch_test_file //第二次更改文件的时间为当前时间,若文件中存有内容,则内容不变
2)[root@localhost Document]# touch -t 06061806 touch_test_file 不创建文件,只是更改文档时间(这里加不加-c操作是一样的)
[root@localhost Document]# touch -t touch_test_file
[root@localhost Document]# ll
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
-rw-r--r--. root root 6月 touch_test_file
3)[root@localhost Document]# touch touch_test_file1 touch_test_file2 将touch_test_file2的时间更改为与touch_test_file1的时间相同
[root@localhost Document]# touch touch_test_file2
[root@localhost Document]# ll
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
-rw-r--r--. root root 6月 touch_test_file //两个文件时间不相同
-rw-r--r--. root root 5月 : touch_test_file2
[root@localhost Document]# touch -r touch_test_file touch_test_file2
[root@localhost Document]# ll
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
-rw-r--r--. root root 6月 touch_test_file //两个文件时间相同
-rw-r--r--. root root 6月 touch_test_file2
4)[root@localhost Document]# touch -d "10 days ago" touch_test_file2 将当前指定文件时间更改为相对现在的过去或未来时间
[root@localhost Document]# touch -d "10 days ago" touch_test_file2
[root@localhost Document]# ll
总用量
drwxrwxr-x. sunjimeng sunjimeng 5月 : bin
drwxrwxr-x. sunjimeng sunjimeng 5月 : Father
-rw-r--r--. root root 6月 touch_test_file
-rw-r--r--. root root 4月 : touch_test_file2 //不是6月6号的10天前,而是当前时间的10天前
5)[root@localhost Document]# touch --help 与touch --version
[root@localhost Document]# touch --help
用法:touch [选项]... 文件...
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 只更改访问时间
-c, --no-create 不创建任何文件
-d, --date=字符串 使用指定字符串表示时间而非当前时间
-f (忽略)
-h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地
(当系统支持更改符号链接的所有者时,此选项才有用)
-m 只更改修改时间
-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 显示此帮助信息并退出
--version 显示版本信息并退出 请注意,-d 和-t 选项可接受不同的时间/日期格式。 GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告touch 的翻译错误
要获取完整文档,请运行:info coreutils 'touch invocation'
[root@localhost Document]# touch --version
touch (GNU coreutils) 8.22
Copyright (C) Free Software Foundation, Inc.
许可证:GPLv3+:GNU 通用公共许可证第3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律范围内没有其他保证。 由Paul Rubin、Arnold Robbins、Jim Kingdon、
David MacKenzie 和 Randy Smith 编写。
(5)其他
说明:
-t time 使用指定的时间值 time 作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:
[[CC]YY]MMDDhhmm[.SS]
这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则touch 将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时 间.由于系统的限制,早于1970年1月1日的时间是错误的。
每天一个Linux命令(4)touch命令的更多相关文章
- linux常用命令:touch 命令
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a ...
- 全网最详细的Linux命令系列-touch命令
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 命令格式: touch [选项]... 文件... 命令参数: -a 或--tim ...
- linux命令之------touch命令
touch命令 1) 作用:用于修改文件或目录的时间属性,包括存取时间和更改时间.若文件不存在,系统会建立一个新的文件. 2) -a:改变档案的读取时间记录: 3) -m:改变档案的 ...
- Linux中的touch命令总结(一)
touch命令有两个主要功能: 改变 timestamps 新建_空白_文件 例如,不带任何参数地输入: touch file1 file2 file3 将在当前目录下新建三个空白文件:file1, ...
- Linux—文件命令之touch命令
下面总结一下对于文件的操作命令: satat命令:用于显示文件的详细信息,包括文件.设备.gid.各种时间等. 命令格式:stat filename touch 的两个功能: 1.新建文件,如需建立特 ...
- 【Linux常见命令】touch命令
touch - change file timestamps touch [文件名] 就是“摸”一下文件,如果文件不存在,就建立新文件:如果文件存在,就改变文件的访问时间atime等时间戳信息. 语法 ...
- 每天一个linux命令:touch(9)
touch touch命令有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来:二是用来创建新的空文件 格式 touch [选项] [文件] 参数 ...
- 每天一个linux命令(9):touch
1.命令简介 touch命令将每个文件的访问时间和修改时间改为当前时间. 2.用法 touch [选项]... 文件... 3.选项 -a 只更改访问时间 -c, --no-create 不创建任何文 ...
- Linux学习历程——Centos 7 touch命令
一.命令介绍 touch 命令用于创建空白文件,以及设置文件的时间. ----------------------------------------------------------------- ...
- Linux Touch命令的8种使用技巧
Linux touch命令不仅可以用于在Linux上创建空文件. 您可以使用它来更改现有文件的时间戳,包括其访问权限和修改时间. 本文介绍了8种可以通过Linux终端使用touch命令的方案. 我们在 ...
随机推荐
- 如何修改myeclipse中web项目的工作路径或默认路径
如何修改myeclipse中web项目的工作路径或默认路径 博客分类: J2EE开发技术指南 安装好myeclipse后,第一次启动myeclipse时,都会弹出会弹出Workspace Laun ...
- Gauge安装
Gauge系列推荐:https://blog.csdn.net/column/details/20089.html Gauge是一种轻量级的跨平台测试自动化工具,可以以业务语言编写测试用例. 安装 下 ...
- scikit-learn---PCA(Principle Component Analysis)---KNN(image classifier)
摘要:PCA为非监督分类方法,常用于数据降维.为监督分类数据预处理,本例采用PCA对人脸特征提取先做降维处理,然后使用KNN算法对图片进行分类 ##1.PCA简介 设法将原来变量重新组合成一组新的互相 ...
- 通过小书匠编辑器让印象笔记和evernote支持markdown编辑
a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2p ...
- macbook 下SDK Manager 的更新[即使Google被屏蔽了也无所谓]
废话少说,直接说操作步骤: 1. 改动/etc/hosts文件: 右键单击Finder,选择前往目录,输入/private/etc/,敲回车键.将文件/etc/hosts复制到桌面(由于权限受限.无法 ...
- [码海拾贝 之Perl]在字符串数组中查找特定的字符串是否存在
前言 检索一个字符串是否存在于一个数组中, 最主要的想法应该就是对数组进行循环, 逐个推断数组的每一个元素值和给定的值是否相等. (在Java语言还能够把数组转成 List , 在 list 中直接有 ...
- linux pptp 服务端安装并正常上网
linux 下 PPTP VPN 1.安装相关软件32位版:yum -y install ppprpm -Uvh http://poptop.sourceforge.net/yum/stable/rh ...
- oracle中建同名
create synonym TD_B_REDIS_COUNT for ucr_param.TD_B_REDIS_COUNT;grant DELETE,UPDATE,INSERT,SELECT on ...
- 解密SVM系列(二):SVM的理论基础(转载)
解密SVM系列(二):SVM的理论基础 原文博主讲解地太好了 收藏下 解密SVM系列(三):SMO算法原理与实战求解 支持向量机通俗导论(理解SVM的三层境界) 上节我们探讨了关于拉格朗日乘 ...
- 如何提高Linux下块设备IO的整体性能?
编辑手记:本文主要讲解Linux IO调度层的三种模式:cfp.deadline和noop,并给出各自的优化和适用场景建议. 作者简介: 邹立巍 Linux系统技术专家.目前在腾讯SNG社交网络运营部 ...