文件操作-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非常重要的一部分,希望大家不要忽略.这篇文章会简单介 ...
随机推荐
- windows如何搭建redis集群
操作系统:win10 64位 redis版本:3.2.1-x64 ruby版本:2.5.1-1-x64 rubygems版本:2.7.6 今天突然想简单的搭建一个redis的集群,因为系统是Windo ...
- Maven多模块构建实例
创建coffee-parent项目 New->Maven Project 创建coffee-web项目 右键coffee-parent项目->New->Project... 注意:需 ...
- JavaSE 帮助文档下载
- mysql整理(个人)
注意:以下命令都是在Linux系统下执行的: 1.验证mysql是否安装成功: mysqladmin --version 2.连接mysql服务器: mysql -u root -p 之后输入密码 3 ...
- python 基础(六) 推导式
列表推导式 概念:提供了一种创建列表的简单快速的途径 (1) 一般形式 myList = [x for x in range(10)] #分解后 myList = [] for x in rang ...
- 普通平衡树与文艺平衡树的splay代码
主要综合借鉴了yyb和马前卒两位大佬的. //普通平衡树 #include <cstdio> #include <cctype> #include <cstring> ...
- GYM 101889I(mst+lca)
最小生成树上倍增询问裸的. const int maxn = 2e5 + 5; int n, m, q; //图 struct Edge { int u, v; ll cost; bool opera ...
- 【aspnetcore】在asp.net core中配置使用AutoMapper
网上使用AutoMapper的文章很多,就不多说了.这里主要记录一下怎么在项目中配置和使用. 首先是从NuGet获取AutoMapper. 在Startup.cs文件中注册AutoMapper服务 p ...
- 记录一下filter
filter是什么,如它的字面意思,就是拦截器.它可以在request到达相关资源之前,比如servlet之前先处理requeset,也可以拦截或处理从某个资源比如servlet发出的response ...
- shell与aw的简单交互示例
先来看一段shell代码 word=“a test name” selectword=“test"lineitem=`echo "$word" | awk 'match( ...