linux命令touch(Ubuntu Touch)

admin 466 0

其实linux命令touch的问题并不复杂,但是又很多的朋友都不太了解Ubuntu Touch,因此呢,今天小编就来为大家分享linux命令touch的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

一、Linux下touch命令有什么作用如何使用

在Linux命令中,我们会经常使用到cd、ls等命令,但像touch这样的命令就比较少用了,那么touch命令有什么作用呢?下面随小编一起来了解下Linux下touch命令的用法吧。

linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件。

-a或--time=atime或--time=access或--time=use只更改存取时间。

-c或--no-create不建立任何文档。

-d使用指定的日期时间,而非现在的时间。

-f此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

-m或--time=mtime或--time=modify只更改变动时间。

-r把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

-t使用指定的日期时间,而非现在的时间。

touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。

[root@localhost test]# touch log2012.log log2013.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

如果log2014.log不存在,则不创建文件

[root@localhost test]# touch-c log2014.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

实例二:更新log.log的时间和log2012.log时间戳相同

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test]# touch-r log.log log2012.log

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

touch-t 201211142234.50 log.log

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test]# touch-t 201211142234.50 log.log

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 2012-11-14 log.log

-t time使用指定的时间值 time作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:

这里,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命令的用法介绍了,使用touch命令可以修改文件时间戳,其修改的是指定日期时间而不是现在时间,你学会了吗?

二、Linux系统下touch命令的使用方法

-a  或--time=atime或--time=access或--time=use只更改存取时间。

  -c  或--no-create不建立任何文档。

  -d使用指定的日期时间,而非现在的时间。

  -f此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

  -m  或--time=mtime或--time=modify只更改变动时间。

  -r把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

  -t使用指定的日期时间,而非现在的时间。

touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。

[root@localhost test]# touch log2012.log log2013.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

如果log2014.log不存在,则不创建文件

[root@localhost test]# touch-c log2014.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

实例二:更新log.log的时间和log2012.log时间戳相同

  -rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  [root@localhost test]# touch-r log.log log2012.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

touch-t 201211142234.50 log.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 10-28 14:48 log.log

  [root@localhost test]# touch-t 201211142234.50 log.log

  [root@localhost test]# ll

  -rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

  -rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

  -rw-r--r-- 1 root root 0 2012-11-14 log.log

-t time使用指定的时间值 time作为指定文件相应时间戳记的新值.此处的 time规定为如下形式的十进制数:

这里,CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数.如果不给出CC的值,则touch  将把年数CCYY限定在1969--2068之内.MM为月数,DD为天将把年数CCYY限定在1969--2068之内.MM为月数,DD为天数,hh为小时数(几点),mm为分钟数,SS为秒数.此处秒的设定范围是0--61,这样可以处理闰秒.这些数字组成的时间是环境变量TZ指定的时区中的一个时间.由于系统的限制,早于1970年1月1日的时间是错误的。

  touch(1)-更新?n案的?r???

  藉由???指令,我??可以同?r或?为??更?n案的?煞N?r???,?取?r?(access time)以及修改?r?(modification time)。

  更改文件的?取?r?(access time)

  更改文件的修改?r?(modification time)

  ?定"特定?r?"?泶??quot;目前?r?",格式 [[CC]YY]MMDDhhmm[.ss]

  ?示程式本身的版本??

  -rw-r--r-- 1 root root 0 7月 9 13:53 file-touch1

一般??r下使用 touch指令?更?n案?r?,如果?n案不存在,touch???咏?⒅付ǖ?n案(空?n案)。如果不想因使用 touch而建立任何新?n案,必?加上??-c

  touch: setting times of `file-touch2':?]有此一?n案或目?

指令的?绦薪Y果是出?一段???息,因?橹付ǖ?n案不存在。?正是加上??-c的目的。更新?n案?r? touch指令一般是以下指令??r的???r??碜?楦??n案的?r?。但也提供特殊的??-t??br/指定"特定的?r?"作?楦??r?。?榱伺e例的方便,我原封不定地,拷?一?已建?n?久的系?程式-- tcsh

  -rwxr-xr-x 1 root root 288604?一 6月 25 03:45:26 2001 tcsh

??程式的最後修改?r?是-- 2001年 6月 25日 3? 45分 26秒。?在,我因?控上的需要,打算??n案?r??更? 2002年 7月 1日 8? 00分 01秒。最??斡行У淖鞣ㄈ缦

# touch-t 200207010800.01 tcsh

  -rwxr-xr-x 1 root root 288604?一 7月 01 08:00:01 2002 tcsh

??的?法很?渭?,就是直接?入西元的年月日?r分?底旨纯桑?溟g不需任何分隔。如果要加上秒?担?龇ū容^特?e,需使用小?"."?砼c前段?^隔。?然,在有需要?r,touch指令也支援"?取?r?"或"修改?r?"的?为??更。

  -rwxr-xr-x 1 root root 288604 7月 2 23:00 tcsh

上例是?为??更"?取?r?",下例?t是?更"修改?r?"

  -rwxr-xr-x 1 root root 288604 6月 30 23:00 tcsh

  -rwxr-xr-x 1 root root 288604 7月 2 23:00 tcsh

以上?些例子,即是大?上 touch的

三、Linux中touch的作用。

1、使用touch命令创建一个单个文件test,执行touchtest,如图所示:

2、使用touch命令同样可以创建多个文件,只需要在后面写上多个文件名字即可,如图所示:

3、使用-a选项可以改变或者更新文件的最新访问时间,如下命令更新文件的访问时间,如果文件不存在,会重新新建一个文件,如图:

4、使用-c选项,可以避免创建一个新文件,并用当前时间更新时间戳,如图:

5、使用-c、-t选项来明确设置文件的时间,例如设置文件test的修改时间和访问时间为12年12月13日10点30分,如图所示:

6、如果想使用文件a的时间戳来更新文件test的时间戳,可以使用命令touch-ratest,如图所示:

END,本文到此结束,如果可以帮助到大家,还望关注本站哦!