Linux Touch Command

Source: Internet
Author: User
Tags touch command

With Touch This command, we can easily modify the date and time of the file, and can also create an empty file. However, it is important to note that even when we copy a file, all properties are copied, but there is no way to copy the CTime property. CTime can record the time when the file's recent state (status) was changed. Anyway, still want to tell everyone, we usually look at the file attributes, the more important or belong to that mtime. What we often care about is when the "content" of this file was changed.

In any case, the most common use of the Touch command is:

Create an empty file;

Modifies a file date to the current date (Mtime and Atime).


Command format:

touch [Options] ... File...

Command parameters:

-A modifies access time only.

-C only modifies the file time and does not create any files.

-D can then be used to modify the date instead of the current date, you can use a variety of different formats.

-F is not used and is reserved for compatibility with other UNIX systems.

-M only changes the change time mtime.

-R Sets the date and time of the specified document or directory to the same date and time as the reference document or directory.

-T uses the specified datetime, rather than the current time, in the same format as the date directive.

command example:

1. Adjust the 123.txt file to the first two days. Current date 2016.4.22

[Email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 16:49 123.txt 22nd [[email protected] zdw]# touch-d "2 days Ago" 123.txt[[email protected] Z dw]# ll 123.txt; ll--time=atime 123.txt; ll--time=ctime 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt

The above example, originally 22nd, became the 20th (atime/mtime)

CTime, however, did not follow the change.

2. Change 123.txt date to 2016/4/10 02:03

[Email protected] zdw]# touch-t 1604100203 123.txt [[email protected] zdw]# ll 123. txt ll--time=atime 123.txt; ll--time=ctime 123.txt-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 4 Apr 16:57 123.txt

The date Atime and mtime have changed, but CTime is the time to record the current.

The 3.-c parameter, if the file does not exist, is not created

[Email protected] zdw]# touch-c 456.txt[[email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 02:03 123.txt

4.-r parameter, update 123.txt time and 456.txt timestamp same, whichever is 123.txt time

[email protected] zdw]# Touch 456.txt[[email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 0 Apr 17:03 456.txt[[email protected] zdw]# touch-r 123.txt 456.txt[[email protected] zdw]# lltotal 4-rw-r --r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 0 Apr 02:03 456.txt


This article is from the blog "Write to Yourself", so be sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1766778

Linux Touch Command

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.