
The touch command without any command line options will create a new, empty file, where the access time (atime), change time (ctime) and modify time (mtime) of the file is the current time. For example, let's say foo.txt is created.
touch foo.txt
The stat command can be used to display the access time, change time and modify time of foo.txt.
~]$ stat foo.txt
File: ‘/home/john.doe/foo.txt’
Size: 0 Blocks: 0 IO Block: 65536 regular empty file
Device: 2fh/47d Inode: 421849 Links: 1
Access: (0644/-rw-r--r--) Uid: (john.doe / john.doe) Gid: ( 2001/admins)
Context: system_u:object_r:nfs_t:s0
Access: 2022-03-30 00:38:40.200196000 -0500
Modify: 2022-03-30 00:38:40.200196000 -0500
Change: 2022-03-30 00:38:40.202215000 -0500
Birth: -
The touch command with the -a and -t options can be used to create a file with a specific access time. In this example, foo.txt is created with an access time of 01/01/2022 at 00:00:00.
touch -a -t 202201010000.00 foo.txt
The stat command can be used to verify that foo.txt has an access time of 01/01/2022 00:00:00.
~]$ stat foo.txt
File: ‘/home/john.doe/foo.txt’
Size: 0 Blocks: 0 IO Block: 65536 regular empty file
Device: 2fh/47d Inode: 421849 Links: 1
Access: (0644/-rw-r--r--) Uid: (john.doe / john.doe) Gid: ( 2001/admins)
Context: system_u:object_r:nfs_t:s0
Access: 2022-01-01 00:00:00.000000000 -0600
Modify: 2022-03-30 00:38:40.200196000 -0500
Change: 2022-03-30 00:38:40.202215000 -0500
Birth: -
Similarly, the touch command with the -m and -t options can be used to create a file with a specific modify time.
touch -m -t 202201010000.00 foo.txt
Or, the access time and modify time can be set as a single command.
touch -a -m -t 202201010000.00 foo.txt
Or, the access time and modify time can be set like this, which has a bit more user friendly format.
touch -d "2022-01-01 00:00:00.000000000 +0530" foo.txt
Did you find this article helpful?
If so, consider buying me a coffee over at