How to change file access time?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 13 2025
076

To change the access time of a file in a Unix-like operating system, you can use the touch command with specific options. Here’s how to do it:

Using touch to Change Access Time

  1. Basic Command:

    touch file1.txt

    This command updates the access time (and modification time) of file1.txt to the current time.

  2. Set a Specific Time:
    If you want to set a specific access time, you can use the -a option along with the -t option:

    touch -a -t YYYYMMDDhhmm file1.txt

    Replace YYYYMMDDhhmm with the desired date and time. For example, to set the access time to January 1, 2023, at 12:00 PM, you would use:

    touch -a -t 202301011200 file1.txt
  3. Using -d Option:
    Alternatively, you can use the -d option to specify a date string:

    touch -a -d "2023-01-01 12:00" file1.txt

Summary of Options:

  • -a: Change only the access time.
  • -t: Specify the time in YYYYMMDDhhmm format.
  • -d: Specify a date string for the access time.

Example:

To change the access time of file1.txt to January 1, 2023, at 12:00 PM:

touch -a -d "2023-01-01 12:00" file1.txt

If you have any more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!