Linux common commands [command] touch

touch - change file timestamps

touch [filename] is the "touch" at the file, if the file does not exist, create a new file; if the file exists, it is time to change the access atime file timestamps and other information.

 

Syntax:
  Touch [OPTION] ... FILE ...

  Touch [- ACFM ] [- D <datetime>] [- R & lt <Reference file or directory>] [- T <datetime>] [- Help ] [- Version ] [file or directory ...]

 

parameter:

  • -a change in the reading file time records.
    • [root@oldboy oldboy]# stat new.txt
        File: `new.txt'
        Size: 120             Blocks: 8          IO Block: 4096   regular file
      Device: 803h/2051d      Inode: 275539      Links: 1
      Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
      Access: 2019-11-06 22:10:48.234818898 +0800
      Modify: 2019-11-07 18:48:17.389776861 +0800
      Change: 2019-11-07 18:48:17.390776816 +0800
      
      [root@oldboy oldboy]# touch new.txt -a
      
      # touch -a修改了atime和ctime
      [root@oldboy oldboy]# stat new.txt    
        File: `new.txt'
        Size: 120             Blocks: 8          IO Block: 4096   regular file
      Device: 803h/2051d      Inode: 275539      Links: 1
      Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
      Access: 2019-11-07 19:49:23.350646538 +0800
      Modify: 2019-11-07 18:48:17.389776861 +0800
      Change: 2019-11-07 19:49:23.350646538 +0800
      touch -a effect

       

  • -m change to modify file time records.
    • [root@oldboy oldboy]# stat new.txt    
        File: `new.txt'
        Size: 120             Blocks: 8          IO Block: 4096   regular file
      Device: 803h/2051d      Inode: 275539      Links: 1
      Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
      Access: 2019-11-07 19:49:23.350646538 +0800
      Modify: 2019-11-07 18:48:17.389776861 +0800
      Change: 2019-11-07 19:49:23.350646538 +0800
      
      [root@oldboy oldboy]# touch new.txt -m
      
      # touch -m 修改了mtime和ctime
      [root@oldboy oldboy]# stat new.txt 
        File: `new.txt'
        Size: 120             Blocks: 8          IO Block: 4096   regular file
      Device: 803h/2051d      Inode: 275539      Links: 1
      Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
      Access: 2019-11-07 19:49:23.350646538 +0800
      Modify: 2019-11-07 19:51:19.971719215 +0800
      Change: 2019-11-07 19:51:19.971719215 +0800
      touch -m effect

       

  • -c,--no-create 
    • do not create any files
    • If the purpose of the file does not exist, does not create a new file.
    • [root@oldboy oldboy]# touch -c nn
      [root@oldboy oldboy]# ls nn
      ls: cannot access nn: No such file or directory
      touch -c Do not create file

       

  • -f
    • ignored
    • Do not use, in order to retain compatibility with other unix systems.
  • -r,--reference=FILE
    • use this file's times instead of current time
    • Recording a reference time profile, with the same effect --file.
  • -d,--date=STRING
    • parse STRING and use it instead of current time
    • Set the time and date, you can use a variety of different formats.
  • -t
    • use [[CC]YY]MMDDhhmm[.ss] instead of current time
    • File recording time set, date format instruction is the same.

 

Example:

1. Check the before and after results of touch file found modified atime, ctime and mtime, modify the time attributes of the file.

[root@oldboy oldboy]# stat name.txt
  File: `name.txt'
  Size: 35              Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 275549      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-11-07 19:46:37.014647959 +0800
Modify: 2019-11-07 19:46:37.014647959 +0800
Change: 2019-11-07 19:46:37.014647959 +0800

[root@oldboy oldboy]# touch name.txt

[root@oldboy oldboy]# stat name.txt 
  File: `name.txt'
  Size: 35              Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 275549      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-11-07 19:47:19.574647813 +0800
Modify: 2019-11-07 19:47:19.574647813 +0800
Change: 2019-11-07 19:47:19.574647813 +0800

 

Guess you like

Origin www.cnblogs.com/zoe233/p/11815178.html