touch命令总结

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了touch命令总结相关的知识,希望对你有一定的参考价值。

touch命令:修改文件时间戳

常用参数:-a,-r,-d,-m;最常用就是不加参数,创建空文件。

[[email protected] ~]# man touch
Formatting page, please wait...
TOUCH(1)                         User Commands                        TOUCH(1)

NAME
       touch - change file timestamps

SYNOPSIS
       touch [OPTION]... FILE...

DESCRIPTION
       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     change only the access time

       -c, --no-create
              do not create any files

       -d, --date=STRING
              parse STRING and use it instead of current time

       -f     (ignored)

       -h, --no-dereference
              affect each symbolic link instead of any referenced file (useful
              only on systems that can change the timestamps of a symlink)

       -m     change only the modification time

       -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: equiv-
              alent to -a WORD is modify or mtime: equivalent to -m

       --help display this help and exit

       --version
              output version information and exit

       Note that the -d and -t options accept different time-date formats.

DATE STRING
       The  --date=STRING  is  a mostly free format human readable date string
       such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29  16:21:42"  or
       even  "next Thursday".  A date string may contain items indicating cal-
       endar date, time of day, time zone, day of week, relative  time,  rela-
       tive date, and numbers.  An empty string indicates the beginning of the
       day.  The date string format is more complex than is easily  documented
       here but is fully described in the info documentation.

常用用法:

1、不加参数,创建空文件

[[email protected] ~]# touch my_test.txt
[[email protected] ~]# ls -lrt my_test.txt 
-rw-r--r-- 1 root root 0 Apr  4 23:54 my_test.txt
[[email protected] ~]#

2、-r参数,用另一个文件的时间来替代当前文件的修改时间。

[[email protected] ~]# ls -lrt my_test.txt 
-rw-r--r-- 1 root root 0 Apr  4 23:54 my_test.txt
[[email protected] ~]# 
[[email protected] ~]# ls -lrt mytest.txt 
-rw-r--r-- 1 root root 1 Apr  3 04:48 mytest.txt
[[email protected] ~]# touch -r mytest.txt my_test.txt 
[[email protected] ~]# ls -lrt my_test.txt 
-rw-r--r-- 1 root root 0 Apr  3 04:48 my_test.txt
[[email protected] ~]#

3、-a参数,只修改文件的访问时间,access time。

[[email protected] ~]# stat my_test.txt 
  File: `my_test.txt‘
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 659269      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-05 00:02:41.503923524 +0800
Modify: 2016-04-03 04:48:27.074468263 +0800
Change: 2016-04-05 00:02:41.503923524 +0800
[[email protected] ~]# touch -a my_test.txt 
[[email protected] ~]# stat my_test.txt 
  File: `my_test.txt‘
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 659269      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-05 00:04:31.903920913 +0800
Modify: 2016-04-03 04:48:27.074468263 +0800
Change: 2016-04-05 00:04:31.903920913 +0800

4、-m参数,只改变文件的修改时间,modify time。

[[email protected] ~]# stat my_test.txt 
  File: `my_test.txt‘
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 659269      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-05 00:04:31.903920913 +0800
Modify: 2016-04-03 04:48:27.074468263 +0800
Change: 2016-04-05 00:04:31.903920913 +0800
[[email protected] ~]# 
[[email protected] ~]# touch -m my_test.txt 
[[email protected] ~]# stat my_test.txt 
  File: `my_test.txt‘
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 659269      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-05 00:04:31.903920913 +0800
Modify: 2016-04-05 00:07:39.838926713 +0800
Change: 2016-04-05 00:07:39.838926713 +0800


本文出自 “攸心斋” 博客,请务必保留此出处http://mofei.blog.51cto.com/6840705/1760129

以上是关于touch命令总结的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统基础命令总结

解决移动端报错:Unable to preventDefault inside passive event listener due to target being treated as……(代码片段

python常用代码片段总结

BootStrap有用代码片段(持续总结)

VSCode自定义代码片段——git命令操作一个完整流程

BootStrap实用代码片段(持续总结)