To change file timestamps in Linux, you can use the touch command. Here are the methods to change the access time (atime) and modification time (mtime):
Change Both Access and Modification Times
To update both timestamps to the current time:
touch filename.txt
Change to a Specific Timestamp
To set a specific timestamp, use the -t option with the format [[CC]YY]MMDDhhmm[.ss]. For example, to set the timestamp to March 15, 2023, at 10:30 AM:
touch -t 202303151030 filename.txt
Change Access Time Only
To change only the access time, use the -a option:
touch -a -d "2023-03-15 10:30" filename.txt
Change Modification Time Only
To change only the modification time, use the -m option:
touch -m -d "2023-03-15 10:30" filename.txt
Change Timestamps Using -d Option
You can also use the -d option for a more human-readable format:
touch -d "2023-03-15 10:30" filename.txt
These commands allow you to modify the timestamps of files as needed.
