Linux Touch and Stat command usage

Source: Internet
Author: User
Tags current time touch command


Stat

Text Editor

We know that the touch is the creation of a file, in fact the touch is used to modify the file timestamp, while the file is three time
Access time records the most recent file access time, as long as a file is opened, meaning that there is a corresponding IO behind, open is a write Io (write access time to disk properties)

Touch command:

[Root@docker-node1 ~]# Touch Linuxea
[Root@docker-node1 ~]# file Linuxea
Linuxea:empty
[Root@docker-node1 ~]#
Touch a file, the file is actually unable to determine the type of files, in the touch of a nonexistent file, the default is to create an empty file, many times the touch is used to create a blank file command, which can be modified by default, the file if there is to change the time stamp, If not, the file will not be created

[Root@docker-node1 ~]# touch-c linuxea1
[Root@docker-node1 ~]# ll Linuxea1
Ls:cannot access linuxea1:no such file or directory
[Root@docker-node1 ~]#
Therefore, if you are simply modifying the timestamp, you can use the-C option

Stat command: Displays the source or attribute information of a file system and file

[Root@docker-node1 ~]# Stat Linuxea
File: ' Linuxea '
size:0 blocks:0 IO block:4096 Regular empty file
device:fd00h/64768d inode:71359973 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:object_r:admin_home_t:s0
Access:2016-07-12 14:23:31.396999492-0400
Modify:2016-07-12 14:23:31.396999492-0400
Change:2016-07-12 14:23:31.396999492-0400
Birth:-
Size: Sizes
Blocks: the disk blocks occupied
IO block: One io pass size
Regular empty file: Files type
Device: Equipment for storage
inode:71359973 inode Number
Links:1: Number of links
Access: (0644/-rw-r--r--): access rights
UID: (0/root): UID owner
GID: (0/root): GID Group
Three time stamps
access:2016-07-12 14:23:31.396999492-0400 Access Time
modify:2016-07-12 14:23:31.396999492-0400 Modification
change:2016-07-12 14:23:31.396999492-0400 State Change Time

Stat View modified timestamp: source time

[root@docker-node1 ~]# stat in.sh
  File: ' in.sh '
  size:134      & nbsp;      blocks:8          IO block:4096    regular file
device:fd00h/64768d    inode:68352533    links:1
Access: (0755/-rwxr-xr-x)   Uid: (    0/    root)    Gid: (     0/    root)
Context:unconfined_u:object_r:admin_home_t:s0
access:2016-07-05 08:51:01.280561305-0400
modify:2016-06-30 14:29:48.428395106-0400
change:2016-06-30 14:29:52.828395524- 0400
 birth:-
[root@docker-node1 ~]#
Touch once, modify to current time:

[Root@docker-node1 ~]# touch in.sh
[root@docker-node1 ~]# stat in.sh
  File: ' in.sh '
  size:13 4             blocks:8           IO block:4096   Regular file
device:fd00h/64768d    inode:68352533    links:1
Access: (0755/-rwxr-xr-x)   Uid: (    0/     root)    Gid: (    0/    root)
Context:unconfined_u:object_r:admin _home_t:s0
access:2016-07-12 14:39:33.524091028-0400
modify:2016-07-12 14:39:33.524091028-0400
Change: 2016-07-12 14:39:33.524091028-0400
 birth:-
[root@docker-node1 ~]#
Touch can also specify a time:-T
Format: br> modified to December 20, 2020 20 o'clock. 20 seconds

[Root@docker-node1 ~]# touch-t 202012202020.20 in.sh
[Root@docker-node1 ~]# Stat in.sh
File: ' in.sh '
size:134 blocks:8 IO block:4096 Regular file
device:fd00h/64768d inode:68352533 links:1
Access: (0755/-rwxr-xr-x) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:object_r:admin_home_t:s0
Access:2020-12-20 20:20:20.000000000-0500
Modify:2020-12-20 20:20:20.000000000-0500
Change:2016-07-12 14:45:23.777124351-0400
Birth:-
[Root@docker-node1 ~]#
As shown above: This shows that stat view can only modify the access time and modification time, the state change time and system current time
[Root@docker-node1 ~]# Date
Tue June 14:45:25 EDT 2016
[Root@docker-node1 ~]#

If you only want to modify the access time to add-a-t

[Root@docker-node1 ~]# touch-a-t 203012202020.20 in.sh
[root@docker-node1 ~]# stat in.sh
  File: ' In.s H '
  size:134             blocks:8           IO block:4096   Regular file
device:fd00h/64768d     inode:68352533    links:1
Access: (0755/-rwxr-xr-x)   Uid: (  & nbsp 0/    root    Gid: (    0/    root)
Context:unconfined_u : Object_r:admin_home_t:s0
access:2030-12-20 20:20:20.000000000-0500
modify:2020-12-20 20:20:20.000000000- 0500
change:2016-07-12 14:47:46.772137955-0400
 birth:-
[Root@docker-node1 ~]#
If you only want to modify the modification time,-m-t Can

[Root@docker-node1 ~]# touch-m-T 204012202020.20 in.sh
[Root@docker-node1 ~]# Stat in.sh
File: ' in.sh '
size:134 blocks:8 IO block:4096 Regular file
device:fd00h/64768d inode:68352533 links:1
Access: (0755/-rwxr-xr-x) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:object_r:admin_home_t:s0
Access:2030-12-20 20:20:20.000000000-0500
Modify:2040-12-20 20:20:20.000000000-0500
Change:2016-07-12 14:51:58.534161908-0400
Birth:-
[Root@docker-node1 ~]#
As long as you modify the source data, whether you are fixing the access time or the modification time, the state change time will become the moment of the current change time

Nano,vim

There are two types of Linux editors from the interface, row editor, one operation line, sed flow editor, and second Full-screen editor, such as Nano,vim,vi

Nano FILE
Nano Common operations
Ctrl+g help
Ctrl+o save
Ctrl+r read
ctrl+y up one page
Ctrl+x exit
Ctrl+w Find
Ctrl + V Scroll down a page
Ctrl+k cut
Ctrl+u cancel

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.