文件操作-touch
本文来给大家介绍另外一个比较常用的命令--touch命令,Linux touch命令 主要用来修改文件或者目录的时间属性,或者建立新文件。
转载自https://www.linuxdaxue.com/linux-command-intro-touch.html
touch 命令
一、Linux touch命令 语法
Linux touch命令 的语法格式主要如下:
touch [OPTION]... FILE...
参数说明:
-a 或--time=atime或--time=access或--time=use 只更改存取时间。
-c 或--no-create 不建立任何文档。
-d 设定时间与日期,可以使用各种不同的格式。
-f 此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。
-m 或--time=mtime或--time=modify 只更改变动时间。
-r 把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。
-t 使用指定的日期时间,而非现在的时间,格式与 date 指令相同。
--help 列出指令格式。
--version 列出版本讯息。
作者信息:
Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith.
二、Linux touch命令 使用实例
1)新建文件file_new
[linuxdaxue.com@/home/linuxdaxue.com]$ls
dir1 src testDir
[linuxdaxue.com@/home/linuxdaxue.com]$touch file_new
[linuxdaxue.com@/home/linuxdaxue.com]$ls
dir1 file_new src testDir
可以看到,新建了一个名叫file_new的文件。
修改时间就是刚才建立文件的时间:
[linuxdaxue.com@/home/linuxdaxue.com]$ll file_new
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 14:19 file_new
2)修改file_new的时间戳
在上个例子中,新建的file_new文件的时间戳是 14:19分,接下来我们使用 touch命令 修改其时间戳。
[linuxdaxue.com@/home/linuxdaxue.com]$ll file_new
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 14:19 file_new
[linuxdaxue.com@/home/linuxdaxue.com]$touch file_new
[linuxdaxue.com@/home/linuxdaxue.com]$ll file_new
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 14:23 file_new
可以看到,其时间戳变为了14:23分,时间戳发生了改变。
3)让file_new的时间戳与其他文件时间戳相同
[linuxdaxue.com@/home/linuxdaxue.com]$ll
total 12
drwxr-xr-x 3 linuxdaxue.com linuxdaxue.com 4096 Jun 15 11:37 dir1
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 16 14:23 file_new
drwxr-xr-x 7 linuxdaxue.com linuxdaxue.com 4096 Jun 15 11:41 src
[linuxdaxue.com@/home/linuxdaxue.com]$touch -r dir1 file_new
[linuxdaxue.com@/home/linuxdaxue.com]$ll
total 12
drwxr-xr-x 3 linuxdaxue.com linuxdaxue.com 4096 Jun 15 11:37 dir1
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Jun 15 11:37 file_new
drwxr-xr-x 7 linuxdaxue.com linuxdaxue.com 4096 Jun 15 11:41 src
可以看到,执行了 touch命令 后,file_new的时间戳与dir1的时间戳相同了。
4)修改file_new时间戳为指定时间
[linuxdaxue.com@/home/linuxdaxue.com]$touch -t 201612312234.50 file_new
[linuxdaxue.com@/home/linuxdaxue.com]$ll file_new
-rw-r--r-- 1 linuxdaxue.com linuxdaxue.com 0 Dec 31 2016 file_new
执行过touch命令后,file_new的时间戳变了2016年12月31号,touch 命令 修改时间的格式如下:
[[CC]YY]MMDDhhmm[.SS]
说明:CC为年数中的前两位,即”世纪数“;
YY为年数的后两位,即某世纪中的年数。如果不给出CC的值,则touch 将把年数CCYY限定在1969--2068之内。
MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒。
这些数字组成的时间是环境变量TZ指定的时区中的一个时间。
由于系统的限制,早于1970年1月1日的时间是错误的。
文件操作-touch的更多相关文章
- 前端学PHP之文件操作
× 目录 [1]文件类型 [2]文件属性 [3]目录路径[4]目录遍历[5]目录统计[6]目录增删[7]目录复制[8]文件操作[9]文件内容 前面的话 在程序运行时,程序本身和数据一般都存在内存中,当 ...
- 前端学PHP之文件操作(认真读读)
前面的话 在程序运行时,程序本身和数据一般都存在内存中,当程序运行结束后,存放在内存中的数据被释放.如果需要长期保存程序运行所需的原始数据,或程序运行产生的结果,就需要把数据存储在文件或数据库.一般地 ...
- php课程---文件操作及文件上传的代码总结
php里面文件包含目录和文件两种 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- PHP 文件操作代码
<?php //echo filetype("./1.jpg"); //判断文件类型 文件:file //echo filetype("./code"); ...
- PHP——文件操作
自己写的: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- php面向对象(文件操作)
文件操作 1.只能操作服务器的文件 2.文件包含目录和文件 判断文件类型 var_dump(filetype("../0529")); //返回文件的类型:目录dir 文件file ...
- Linux文件操作常用命令整理
收集.整理日常系统管理或维护当中的,常用到的一些关于文件操作的命令或需求,后续会慢慢补充.完善! 查看.生成指定目录的目录树结构? [root@DB-Server ~]#tree #当前目录 ...
- 分享:perl 文件操作总结
发布:thebaby 来源:net [大 中 小] perl 文件操作,包括打开.关闭文件,读取.定入文件等.原文链接:http://www.jbxue.com/article/3153.html 打 ...
- PHP 关于文件操作的简单介绍
文件操作一直是Web程序员头疼的地方,而文件操作在CMS这样的系统中又是必须的.如今,PHP文件操作的函数内容已经非常强大,文件这部分也是学习PHP非常重要的一部分,希望大家不要忽略.这篇文章会简单介 ...
随机推荐
- python的pip管理工具
Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. 在此进行编译安装pip ...
- HDU4035(概率期望、树形、数学)
和ZOJ3329有些像,都是用期望列出来式子以后,为了解式子,设A[i],B[i],此题又多了C[i],然后用递推(此题是树形dp)去求得ABC,最后结果只跟ABC有关,跟列写的期望数组根本无关. 虽 ...
- Connected Components? Codeforces - 920E || 洛谷 P3452 &&bzoj1098 [POI2007]BIU-Offices
https://codeforces.com/contest/920/problem/E https://www.luogu.org/problemnew/show/P3452 https://www ...
- Unity Shader入门精要学习笔记 - 第3章 Unity Shader 基础
来源作者:candycat http://blog.csdn.net/candycat1992/article/ 概述 总体来说,在Unity中我们需要配合使用材质和Unity Shader才能达 ...
- CSS Secrets 翻译笔记 01: CSS coding tips
.firDemoButton{ padding: 6px 16px; border: 1px solid #446d88; background: #58a linear-gradient(#77a0 ...
- phpstorm类似sublime ctrl + alt +down多光标下移
http://blog.jetbrains.com/phpstorm/2014/03/working-with-multiple-selection-in-phpstorm-8-eap/ 评论有一条回 ...
- 【Linux】使用Cockpit进行主机管理
Cockpit 进行主机监控 官网文档: https://cockpit-project.org/running.html 版本信息 针对Red Hat [root@master ~]# cat /e ...
- [POJ1185][NOI2001]炮兵阵地 状压DP
题目链接:http://poj.org/problem?id=1185 很裸的状压,考虑对于一行用二进制储存每一种的状态,但是状态太多了做不了. 观察到有很多状态都是不合法的,于是我们预处理出合法的状 ...
- 进程间通信,把字符串指针作为参数通过SendMessage传递给另一个进程,不起作用
参数发送进程: CString csCmd=AfxGetApp()->m_lpCmdLine; if (!csCmd.IsEmpty()) { pWndPrev->SendMessage( ...
- MoveWindow和SetWindowPos
SetWindowPos即使里面使用的是一样的矩形参数,有时候SetWindowPos还是会改变窗口的大小,真是坑爹!!! MoveWindow就不会改变 mark一下