Simple Linux Command Line notes: Touch

Source: Internet
Author: User
ArticleDirectory
    • Parameters
    • Option
    • Example
    • Tips

File Creation or modification time

Touch [Options]File-list

 

Parameters

File-listYesTouchPath Name of the file to be created or updated

 

Option

-A only updates the access time without changing the modification time.

-C. Do not create a nonexistent file

-M: only updates the modification time without changing the access time.

-R file: use the file time to update the file time.

-T change the time to the date specified by the parameter. For example, 07081556 indicates, January 1, July 8.

 

Example Touch updates existing files
$Ls-L firefox_wallpaper.png-RW-r --1Siu309597December20 15:03Firefox_wallpaper.png $TouchFirefox_wallpaper.png $Ls-L firefox_wallpaper.png-RW-r --1Siu309597January8 15:18Firefox_wallpaper.png

Touch does not have the option. It updates the file modification time and access time at the same time.

 

Touch creates a file
$TouchDemo. C $Ls-L total usage372-RW-r --1Siu0January8 15:21Demo. c

 

Touch-

First, check the original modification time and access time. The LS-lu command is used to view the access time.

$Ls-L total usage68-RW-r --1Siu66350December23 16:51Hs_err_pid2874.log $Ls-Total Lu usage68-RW-r --1Siu66350January8 15:17Hs_err_pid2874.log

Next is the updated modification time and access time.

$Touch-01081010Hs_err_pid2874.log $Ls-L total usage68-RW-r --1Siu66350December23 16:51Hs_err_pid2874.log $Ls-Total Lu usage68-RW-r --1Siu66350January8 10:10Hs_err_pid2874.log

We can see that the modification time has not changed, but the access time has changed.

 

Touch-m only updates the modification time
$ Ls - L total usage  68 -RW-r -- 1 Siu 66350 December 23   16 : 51  Hs_err_pid2874.log $  Touch - M hs_err_pid2874.log $  Ls - L total usage 68 -RW-r -- 1 Siu 66350 January 8   15 : 31  Hs_err_pid2874.log $  Ls - Total Lu usage  68 -RW-r -- 1 Siu 66350 January 8   10 :10 Hs_err_pid2874.log

The preceding example shows that the access time has not changed, but the modification time has changed.

 

Tips

1. You can use the default current time to update the file access time and modification time, or you can specify parameters to update files.

2. Generally, the most commonly used part of touch is creating new files.

 

 

 

 

 

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.