Linux File touch command and file Timestamp

Source: Internet
Author: User
Tags touch command

Linux File touch command and file Timestamp
1. Check the time attribute of the file before naming touch. Run the stat command to view the File: [root @ localhost test] # stat f1 File: 'f1' Size: 34 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 72757 Links: 1 Access: (0640/-rw-r -----) Uid: (0/root) Gid: (0/root) Access: 01:26:41. 658883440 + 0800 Modify: 04:05:15. 000000000 + 0800 Change: 20:20:32. 811903158 + 0800 view the preceding information and see the three attributes of the file, "Acess time", that is, the file access time, or "Last read time", such as touch, cat, and more. This value will be modified, but ls and stat will not be used for viewing. Note: If you are using a virtual machine test, you will find that commands such as cat and more are not updated in real time. You can use a physical machine for testing. Modify time: the time when the file was last modified. The ls command displays the time by default. Change time: indicates the last modification time of the file attribute, such as the permission and name, which must be differentiated from Modify time. 2. touch command: used to modify the file timestamp or create a new file. 1. The option parameter-a: -- time = atime Acess time;-m: -- time = mtime Modify time;-c: -- no-create does not create any documents. By default, a file is created when the file does not exist.-c can not create a file. -R: set the date and time of the file to be the same as that of the reference file. -T: Use the specified time and date instead of the system time. Iii. instance 1: touch an existing File [root @ localhost test] # stat f1 File: 'f1' Size: 34 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 71660 Links: 1 Access: (0640/-rw-r -----) Uid: (0/root) Gid: (0/root) Access: 17:28:43. 853828458 + 0800 Modify: 04:05:15. 000000000 + 0800 Change: 03:16:57. 117877086 + 0800 [root @ localhost test] # touch f1 [root @ localhost test] # stat f1 # You can see that all files are updated to the current system time. File: 'f1' Size: 34 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 71660 Links: 1 Access: (0640/-rw-r -----) Uid: (0/root) Gid: (0/root) Access: 18:17:22. 936820504 + 0800 Modify: 18:17:22. 936820504 + 0800 Change: 18:17:22. 936820504 + 0800 [root @ localhost test] # dateFri Oct 9 18:17:29 CST 2015 2, use the touch command to create a file [root @ localhost test] # touch-c f3 #-c without creating a file [Root @ localhost test] # lsf1 f2 test [root @ localhost test] # touch f3 # Create File f3 [root @ localhost test] # lsf1 f2 f3 test [root @ localhost test] # file f3 # view the f3 file type, it is displayed as null f3: empty 3, and the file modification time is specified. You can use man to view the touch-t parameter:-t STAMP use [[CC] YY] MMDDhhmm [. ss] instead of currenttime [root @ localhost test] # touch-t201510081010.10 f3 [root @ localhost test] # stat f3 # Change Time to specified time date File: 'F3' Size: 4 Blocks: 8 IO Block: 4096 regular FileDevice: fd00h/64768d Inode: 66037 Links: 1 accesskey: (0644/-rw-r --) Uid: (0/root) Gid: (0/root) Access: 10:10:10. 000000000 + 0800 Modify: 10:10:10. 000000000 + 0800 Change: 18:34:22. 535825523 + 0800 # note that Ctime is the current time because the file attribute is changed. 4. Align the file time with the specified reference file time. [Root @ localhost test] # touch-r f3 f1 # change the f1 time to be the same as f3 [root @ localhost test] # stat f1 File: 'f1' Size: 34 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 71660 Links: 1 Access: (0640/-rw-r -----) Uid: (0/root) Gid: (0/root) Access: 10:10:10. 000000000 + 0800 Modify: 10:10:10. 000000000 + 0800 Change: 18:42:47. 175819324 + 0800 # The current Ctime is the same. Conclusion: The touch command is relatively simple, mainly to understand the three time attributes of the file.

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.