If you want to change the creation date time, modified date time or access date time of a file in Linux, this blog post is for you.
How to change the date of a file in Linux
Table of Contents
- Use
stat
to print filename attributes - We will test it on our
.vimrc
file - Change the datetime of .vimrc to 2 days ago
- Change the datetime of .vimrc to a specific date and time
- Change the datetime of .vimrc to a date and time relative to current date and time
- To backdate all files in a directory to 24 hours earlier
- How do I change the CREATION DATE / CREATION DATETIME?
- Conclusion
Use stat
to print filename attributes
In Linux, we use the stat
command to find the attributes of a file. The datetime attributes of a file include these:
- accessed time
- modified time
- created time
We will test it on our .vimrc
file
For our example, we will check the datetime attributes of our file .vimrc
.
$ ls -al .vimrc -rw-r--r-- 1 arul arul 291 Dec 31 2024 .vimrc $ stat .vimrc File: .vimrc Size: 291 Blocks: 8 IO Block: 4096 regular file Device: 8,0 Inode: 262490 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ arul) Gid: ( 1000/ arul) Access: 2025-08-04 14:49:31.547412534 -0400 Modify: 2024-12-31 12:11:07.677639387 -0500 Change: 2024-12-31 12:11:07.677639387 -0500 Birth: 2024-12-31 12:11:07.677639387 -0500
As you can see, from the "Birth" key, this .vimrc
file was created on December 31, 2024 at 12:11am.
From the "Access" key, we can see that it was accessed a few hours ago today, August 4, 2024, at 2:49pm.
From the "Modified" key, we see that it has never been modified.
Change the datetime of .vimrc to 2 days ago
Today's date is August 4, 2025.
To change the date of .vimrc
to August 2, that is 2 days ago, we use this syntax:
SYNTAX:
touch -d "2 days ago" <FILENAME>
Let us do it on .vimrc
. This is the output:
$ touch -d "2 days ago" .vimrc
$ ls -al .vimrc
-rw-r--r-- 1 arul arul 291 Aug 2 19:12 .vimrc
$ stat .vimrc
File: .vimrc
Size: 291 Blocks: 8 IO Block: 4096 regular file
Device: 8,0 Inode: 262490 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ arul) Gid: ( 1000/ arul)
Access: 2025-08-02 19:12:49.582438245 -0400
Modify: 2025-08-02 19:12:49.582438245 -0400
Change: 2025-08-04 19:12:49.575863975 -0400
Birth: 2024-12-31 12:11:07.677639387 -0500
The modification date has been set to exactly 2 days ago, and is now 2025-08-02.
Change the datetime of .vimrc to a specific date and time
To change the date of .vimrc
to June 30, 2024, 10:00am, we use this syntax:
SYNTAX:
touch -a -m -t <YYYYMMDDhhmm[.ss]> <FILENAME>
Let us do it on .vimrc
. This is the output:
$ touch -a -m -t 202406301000 .vimrc
$ ls -al .vimrc
-rw-r--r-- 1 arul arul 291 Jun 30 2024 .vimrc
$ stat .vimrc
File: .vimrc
Size: 291 Blocks: 8 IO Block: 4096 regular file
Device: 8,0 Inode: 262490 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ arul) Gid: ( 1000/ arul)
Access: 2024-06-30 10:00:00.000000000 -0400
Modify: 2024-06-30 10:00:00.000000000 -0400
Change: 2025-08-04 19:33:53.753749076 -0400
Birth: 2024-12-31 12:11:07.677639387 -0500
Change the datetime of .vimrc to a date and time relative to current date and time
To change the date of .vimrc
5 days before the current datetime of June 30, 2024, 10:00am, we use this syntax:
SYNTAX:
touch -d "$(date -R -r <FILENAME>) - 5 days" <FILENAME>
Let us do it on .vimrc
. This is the output:
$ touch -d "$(date -R -r .vimrc) - 5 days" .vimrc
$ ls -al .vimrc
-rw-r--r-- 1 arul arul 291 Jun 25 2024 .vimrc
$ stat .vimrc
File: .vimrc
Size: 291 Blocks: 8 IO Block: 4096 regular file
Device: 8,0 Inode: 262490 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ arul) Gid: ( 1000/ arul)
Access: 2024-06-25 10:00:00.000000000 -0400
Modify: 2024-06-25 10:00:00.000000000 -0400
Change: 2025-08-04 19:36:27.934953666 -0400
Birth: 2024-12-31 12:11:07.677639387 -0500
To backdate all files in a directory to 24 hours earlier
As an example, if you want to backdate *.conf files in a directory /srv/files
to exactly 24 hours earlier, you can do something like this on the terminal or in a shell script.
find /srv/files/*.conf -print | while read filename; do
touch -d "24 hours ago" $filename
done
How do I change the CREATION DATE / CREATION DATETIME?
Sorry, you cannot change the creation datetime of a file.
Most Linux / Unix systems and file systems prohibit you from being able to change the "Birth" key. There may be ways to get around this, but I have never seen a working solution.
Conclusion
That's all folks! If you found this blog post useful, or just want to say hello, do comment below, or send me an email.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.