A Linux touch command every day

Source: Internet
Author: User
Tags syslog touch command

Linux touch commands are not commonly used, and are generally used when using make, to modify file timestamps, or to create a new file that does not exist.


There are three timestamps of the file (available stat Viewing):

Access time: Atime, reading the contents of a file

Modify Time: Modified, Mtime, change file contents (data)

Change time: Changing times, ctime, meta data changes


1. command format:

Touch [options] ... File ...

2. Command parameters:

-a or--time=atime or--time=access or--time=use only Change access timestamp

- C or--no-create do not create any documents

- m or--time=mtime or--time=modify only change the modified timestamp

-T uses the specified date time instead of the current time

3. Command function:

The touch command parameter changes the date time of the document or directory, including access time and change time.

4. Examples of use:

instance One: Create a file that does not exist

Command:

Touch Log.txt

Output:

[begin] 2015/12/23 13:35:22[[email protected] ~]#  lsanaconda-ks.cfg  install.log  install.log.syslog  text[[email  PROTECTED] ~]# TOUCH LOG.TXT[[EMAIL PROTECTED] ~]# LLTOTAL 64-RW-------.  1 root root  3328 dec 19 05:42 anaconda-ks.cfg-rw-r--r--.  1  root root 39935 dec 19 05:42 install.log-rw-r--r--.  1 root  Root  9154 dec 19 05:39 install.log.syslog-rw-r--r--  1 root  root     0 dec 23 05:36 log.txtdrwxr-xr-x  3  root root  4096 dec 22 16:09 text[end] 2015/12/23 13:36:02 

 

[Begin] 2015/12/23 14:07:07[[email protected] ~]# stat text  file:   ' text '   Size: 4096      Blocks: 8           io block: 4096   directorydevice: 802h /2050dinode: 401425      links: 3access:  (0755/drwxr-xr-x)    Uid:  (    0/    root)    Gid:  (     0/    root) access: 2015-12-22 16:10:05.975041002 - 0800modify: 2015-12-22 16:09:57.538043360 -0800change: 2015-12-22 16:09:57.538043360  -0800[[email protected] ~]# datewed dec 23 06:07:31 pst 2015[[ email protected] ~]# touch -a text[[email protected] ~]# stat  text  file:  ' text '   size: 4096      blocks: 8           io block: 4096   directorydevice: 802h/2050dinode:  401425      Links: 3Access:  (0755/drwxr-xr-x)   uid:   (    0/    root)    Gid:  (     0/    root) access: 2015-12-23 06:07:51.421979327 -0800modify:  2015-12-22 16:09:57.538043360 -0800change: 2015-12-23 06:07:51.421979327 -0800[[email  protected] ~]# datewed dec 23 06:08:07 pst 2015[end] 2015/12/23  14:08:00

Description: The access timestamp for text was changed from 2015-12-22 16:10:05 to 2015-12-23 06:07:51, synchronized with the time of date, because the text metadata changed, so the change time of text changed.

example Three: Do not create any documents

Command:

Touch-c text

Output :

[BEGIN] 2015/12/23 14:13:05[[email protected] ~]# [[email protected] ~]# lsanaconda-ks.cfg install.log install.log.syslo G Log.txt text[[email protected] ~]# touch-c text1[[email protected] ~]# lsanaconda-ks.cfg install.log install.log.sy Slog Log.txt Text[end] 2015/12/23 14:13:29

Example four:

Command:

Touch-m text

output:

[Begin] 2015/12/23 14:20:51[[email protected] ~]# stat text  file:   ' text '   Size: 4096      Blocks: 8           io block: 4096   directorydevice: 802h /2050dinode: 401425      links: 3access:  (0755/drwxr-xr-x)    Uid:  (    0/    root)    Gid:  (     0/    root) access: 2015-12-23 06:21:14.894978504 - 0800modify: 2015-12-22 16:09:57.538043360 -0800change: 2015-12-23 06:07:51.421979327  -0800[[email protected] ~]# touch -m text[[email protected] ~]#  stat text/  file:  ' text/'   Size: 4096       blocks: 8          io block: 4096   directorydevice:  802h/2050dinode: 401425      links: 3access:  (0755/drwxr-xr-x)   Uid:  (    0/    root)    Gid:  (     0/    root) access: 2015-12-23 06:21:14.894978504 - 0800modify: 2015-12-23 06:21:53.599978353 -0800change: 2015-12-23 06:21:53.599978353  -0800[end] 2015/12/23 14:21:53

Description: The modified timestamp of text was changed from 2015-12-22 16:09:57 to 2015-12-23 06:21:53, synchronized with the time of date, because the text metadata changed, so the change time of text changed.


Example five: Setting the access timestamp and modification timestamp of the file

Command:

touch-t 201608301830.55 text 201608301830.55 refers to August 30, 2016 18:30 55 seconds

[Begin] 2015/12/23 14:37:31[[email protected] ~]# stat text  file:   ' text '   Size: 4096      Blocks: 8           io block: 4096   directorydevice: 802h /2050dinode: 401425      links: 3access:  (0755/drwxr-xr-x)    Uid:  (    0/    root)    Gid:  (     0/    root) access: 2015-12-23 06:37:31.563977563 - 0800modify: 2015-12-23 06:37:31.563977563 -0800change: 2015-12-23 06:37:31.563977563  -0800[[email protected] ~]# touch -t 201608301830.55 text[[email  protected] ~]# stat text  file:  ' text '   Size: 4096       blocks: 8          io block: 4096    Directorydevice: 802h/2050dinode: 401425      links: 3access:   (0755/drwxr-xr-x)   Uid:  (    0/    root)     Gid:  (    0/    root) access: 2016-08-30  18:30:55.000000000 -0700modify: 2016-08-30 18:30:55.000000000 -0700change: 2015-12-23  06:38:23.520977454 -0800[end] 2015/12/23 14:38:24

Description: The access and modification timestamp for text was changed from 2015-12-23 06:37:31 to 2016-08-30 18:30:55 because it only sets the timestamp of text, so the metadata for text has not changed, so changing the timestamp does not change.


A Linux touch command every day

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.