How to change file modification time?

QuestionsQuestions4 SkillsProBasic Files OperationsSep, 12 2025
0264

To change the file modification time in Linux, you can use the touch command with the -m option. Here’s how to do it:

  1. Change to the Current Time: To update the modification time of a file to the current time, simply use:

    touch filename.txt
    
  2. Set a Specific Modification Time: To set a specific modification time, you can use the -t option followed by the desired timestamp in the format [[CC]YY]MMDDhhmm[.ss]. For example, to set the modification time to January 1, 2023, at 12:00 PM:

    touch -t 202301011200 filename.txt
    
  3. Using a Reference File: You can also set the modification time of a file to match another file's modification time using the -r option:

    touch -r reference_file.txt target_file.txt
    

These commands allow you to effectively change the modification time of files in the Linux file system.

0 Comments

no data
Be the first to share your comment!