List of Topics
1) About Touch Command and its uses
2) Available time stamp's
3) How to Check time stamp of a file
4) Command line options to modify time stamp
1) About Touch Command and its uses
Everyone is aware that “touch” is the command to create an empty file but apart from that touch command is mainly used to change the time stamp's of the file.
2) Available Time stamp's
Every file/folder in linux has below three time stamps
a) Last access time
b) Last Modification Time
c) Last Change time
Whenever we create a file above mentioned time stamp's will be updated automatically.
3) How to check time stamp of a file
We can change the above time stamp's with the help of touch command.
Before modifying will first
see how to check these time stamps. To check these time stamps we need to use "stat" command. An Sample output of stat command.
[XXXX@server2 ~]# stat
test_file
File:
`test_file'
Size: 0
Blocks: 0
IO Block: 4096 regular empty file
Device: fd00h/64768d
Inode: 791598 Links: 1
Access:
(0644/-rw-r--r--) Uid: ( 0/ root) Gid: (
0/ root)
Access: 2017-03-07
02:19:25.612999258 +0530
Modify: 2017-03-07
02:19:25.612999258 +0530
Change: 2017-03-07
02:19:25.612999258 +0530
4) Command line options to modify time stamp
Below are the command line options to be used with touch command to change the access and modification time
Note: It is not possible to change ctime using touch command
(i) -a -> To Change access time alone. To Change the access time of the file just execute touch -a <filename>. By default it will take the current time and update the access time
(ii) -m -> Similar to -a option just use -m to change the file modification time.
(iii) -r -> This will copy the timestamp from another file eg: touch <file1> -r <file2>
(iv) -t & -d -> this options are used to explicitly change the time to our value.
Syntax -> touch
-t [[Century]YY]MMDDhhmm[.ss]
touch -d "YYYY-MM-DD hh:mm:ss" <filename>
No comments:
Post a Comment