Linux touch 命令使用介绍
文章目录
- 1.命令格式
- 2.命令参数
- 3.命令功能
- 4.使用范例
- 1、创建不存在的文件,用法如下
- 2、更新text.txt 的时间和text3.txt时间戳相同
- 3、设定文件的时间戳
- -t time 格式详细说明
linux中的touch命令一般用来修改文件时间戳,或者新建一个不存在的文件。相关linux 命令的文章中所用到的测试文件都是用 touch 创建出来的,创建目录则是mkdir。
1.命令格式
touch [选项]… 文件…
2.命令参数
-a,–time=atime,–time=access或–time=use 只更改存取时间。
-c 或–no-create不建立任何文档。
-d 使用指定的日期时间,而非现在的时间。
-f 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。
-m 或–time=mtime或–time=modify 只更改变动时间。
-r 把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。
-t 使用指定的日期时间,不是当前时间。
3.命令功能
touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间;创建新的文件 。
4.使用范例
1、创建不存在的文件,用法如下
命令:
touch text.txt text1.txt text2.txt
输出:
lighthouse@VM-4-14-ubuntu:~/touch$ touch text.txt text1.txt text2.txt
lighthouse@VM-4-14-ubuntu:~/touch$ tree
.
├── text1.txt
├── text2.txt
└── text.txt0 directories, 3 files
不创建text3.txt,参数使用 -c
lighthouse@VM-4-14-ubuntu:~/touch$ touch -c text3.txt
lighthouse@VM-4-14-ubuntu:~/touch$ tree
.
├── text1.txt
├── text2.txt
└── text.txt0 directories, 3 files
2、更新text.txt 的时间和text3.txt时间戳相同
命令:
touch -r text3.txt text.txt
先新建text3.txt,再修改时间(使得和之前的文件时间不同)
输出:
lighthouse@VM-4-14-ubuntu:~/touch$ touch text3.txt
lighthouse@VM-4-14-ubuntu:~/touch$ ll
total 8
drwxrwxr-x 2 lighthouse lighthouse 4096 Jun 29 14:29 ./
drwxr-xr-x 9 lighthouse lighthouse 4096 Jun 29 14:22 ../
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text1.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text2.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text3.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text.txt
lighthouse@VM-4-14-ubuntu:~/touch$ touch -r text3.txt text.txt
lighthouse@VM-4-14-ubuntu:~/touch$ ll
total 8
drwxrwxr-x 2 lighthouse lighthouse 4096 Jun 29 14:29 ./
drwxr-xr-x 9 lighthouse lighthouse 4096 Jun 29 14:22 ../
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text1.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text2.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text3.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text.txt
原来 Jun 29 14:23 text.txt,修改后Jun 29 14:29 text.txt,变成了 text3.txt的时间,注意,被修改的文件是后面的参数
3、设定文件的时间戳
命令:
touch -t 202202291437.50 text.txt
输出:
lighthouse@VM-4-14-ubuntu:~/touch$ ll
total 8
drwxrwxr-x 2 lighthouse lighthouse 4096 Jun 29 14:29 ./
drwxr-xr-x 9 lighthouse lighthouse 4096 Jun 29 14:22 ../
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text1.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text2.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text3.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text.txt
lighthouse@VM-4-14-ubuntu:~/touch$ touch -t 202206291437.50 text.txt
lighthouse@VM-4-14-ubuntu:~/touch$ ll
total 8
drwxrwxr-x 2 lighthouse lighthouse 4096 Jun 29 14:29 ./
drwxr-xr-x 9 lighthouse lighthouse 4096 Jun 29 14:22 ../
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text1.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:23 text2.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:29 text3.txt
-rw-rw-r-- 1 lighthouse lighthouse 0 Jun 29 14:37 text.txt
lighthouse@VM-4-14-ubuntu:~/touch$
修改前:29 14:29 text.txt
修改后:29 14:37 text.txt
-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 touch 命令使用介绍相关推荐
- linux中touch命令如何使用,Linux Touch命令的8种常见用法
除了在Linux上简单地创建一个空文件之外,Linux touch命令还有更多的用途.您也可以使用它来更改现有文件的时间戳,包括它们的访问和修改时间.本文介绍了8种通过Linux终端使用touch命令 ...
- linux touch命令 全称,【收藏】Linux常用命令全称及讲解(八)
今天小编要跟大家分享的文章是关于Linux常用命令全称及讲解(八).从事IT行业的很多人都会使用Linux常用命令,但是知道这些常用命令全称的人并不多,让我们来看看这些常用命令对应的全称吧!小编精心整 ...
- Linux rm命令、Linux touch命令、Linux tee命令
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. Linux rm命令用于删除一个文件或者目录. 语法 rm [options] name...[op ...
- linux维护rpm 数据库,Linux运维知识之linux rpm命令详细介绍
本文主要向大家介绍了Linux运维知识之linux rpm命令详细介绍,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助. 虽然现在N多人都使用yum去替代rpm了,但是rpm在一些 ...
- Linux shell命令示例介绍-个人笔记
转载: https://blog.csdn.net/zhangwu1241/article/details/60871000 Linux中命令示例介绍-个人笔记 为了方便以后查阅,会对在Linux学习 ...
- c语言 touch新建文件,C 语言实现 Linux touch 命令
南通大学信息科学技术学院 实验名称:实验十一 C语言实现Linux touch命令 实验日期:2020年6月24日 班级:物联网182 姓名:陈宇腾 学号:1813061044 一.实验预习报告 1. ...
- linux cut最后一列,LINUX CUT命令的介绍
使用cut命令获取文档中的某一列的数据,例如下面的文件cut.tab中间使用tab键分隔,这里要想只显示第3个列区域的内容,可以使用 cut -f3 cut.tab实现.下面学习啦小编就跟大家说说LI ...
- Linux crond命令使用介绍
目录 前言 一.crond简介 系统任务调度 用户任务调度 二.crond服务 三.crontab命令详解 1.命令格式 2.命令功能 3.命令参数 4.常用方法 1). 创建一个新的crontab文 ...
- 【Linux】一步一步学Linux——touch命令(33)
00. 目录 文章目录 00. 目录 01. 命令概述 02. 命令格式 03. 常用选项 04. 参考示例 05. 扩展 06. 附录 01. 命令概述 touch命令有两个功能:一是创建新的空文件 ...
最新文章
- LeetCode 873. 最长的斐波那契子序列的长度 题目详解
- win7下设置无线上网
- CIO都在用的数据可视化软件
- 超全!常见自动化运维工具全解析(含ansible、Puppet、SaltStack教程)
- Echarts.js下载及简易Demo
- 考研心得--一个差劲的ACMer
- 新西兰计算机设计专业,2020年出国新西兰学习计算机专业的要求是什么?
- 写在最后——如何做好一个语音助手
- [20190227]Windows系统评估工具winsat.txt
- 构造-牛客寒假集训营3-牛牛的DRB迷宫II
- 英特尔对手机的几个痛苦领悟
- 马蹄疾 | 详解 JavaScript 异步机制及发展历程(万字长文)
- 利用全加器实现7段数码管_简单共阴极数码管电路图大全(CD4511/段译码/驱动器)...
- mvn scm 作用
- 聊城市普通话水平测试软件音频,聊城市普通话水平测试培训-聊城市教师教育网.ppt...
- 旅游行业数字化进程分析——2023年元旦与春节,旅游市场开启复苏模式,跨省游热度上升
- newman的基本使用
- JAVA多线程终止线程、退出线程、Interrupt()方法、苦逼的搬砖工
- Retrofit2 工作原理解析(一)
- 英特尔、广东联通、广和通联合发布定制物联网模块产品“沃芯”