How to change a file’s modification date and time
Typically, for each file or a directory, the Linux/Unix system maintains three time stamps: “Access”, “Modify” and “Change”. The command “stat” can be used to get the information as shown below.
[neo@techpulp ~]# stat face.jpg File: `face.jpg' Size: 3689673 Blocks: 7216 IO Block: 4096 regular file Device: 823h/2083d Inode: 812120 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ neo) Gid: ( 500/ neo) Access: 2009-01-23 01:15:31.000000000 +0530 Modify: 2009-01-23 01:15:29.000000000 +0530 Change: 2009-01-23 01:15:29.000000000 +0530 [neo@techpulp ~]#
A Linux command-line utility “touch” can be used to modify the time stamps of a file. By default, this command typically changes the file’s access and modification time to the current time. However you can specify custom date and time to set as Modify and Access time stamps.
[neo@techpulp ~]# touch face.jpg [neo@techpulp ~]# stat face.jpg File: `face.jpg' Size: 3689673 Blocks: 7216 IO Block: 4096 regular file Device: 823h/2083d Inode: 812120 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ neo) Gid: ( 500/ neo) Access: 2009-01-23 01:19:58.000000000 +0530 Modify: 2009-01-23 01:19:58.000000000 +0530 Change: 2009-01-23 01:19:58.000000000 +0530 [neo@techpulp ~]#
You can see the time stamps being changed to the current time in the above example. The following example shows how to set custom time stamp:
[neo@techpulp ~]# touch -d '1 Jan 2000 00:01' face.jpg [neo@techpulp ~]# stat face.jpg File: `face.jpg' Size: 3689673 Blocks: 7216 IO Block: 4096 regular file Device: 823h/2083d Inode: 812120 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ neo) Gid: ( 500/ neo) Access: 2000-01-01 00:01:00.000000000 +0530 Modify: 2000-01-01 00:01:00.000000000 +0530 Change: 2009-01-23 01:22:23.000000000 +0530 [neo@techpulp ~]#
It is not mandatory that you should provide date and time always. You can also specify just date or time as shown below.
[neo@techpulp ~]# touch -d '31 Dec 2001' face.jpg [neo@techpulp ~]# stat face.jpg File: `face.jpg' Size: 3689673 Blocks: 7216 IO Block: 4096 regular file Device: 823h/2083d Inode: 812120 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ neo) Gid: ( 500/ neo) Access: 2001-12-31 00:00:00.000000000 +0530 Modify: 2001-12-31 00:00:00.000000000 +0530 Change: 2009-01-23 01:24:38.000000000 +0530 [neo@techpulp ~]# [neo@techpulp ~]# touch -d '11:59:59' face.jpg [neo@techpulp ~]# stat face.jpg File: `face.jpg' Size: 3689673 Blocks: 7216 IO Block: 4096 regular file Device: 823h/2083d Inode: 812120 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 500/ neo) Gid: ( 500/ neo) Access: 2009-01-23 11:59:59.000000000 +0530 Modify: 2009-01-23 11:59:59.000000000 +0530 Change: 2009-01-23 01:25:15.000000000 +0530 [neo@techpulp ~]#


about 3 years ago
Nice article. Is there a way to change the file creation date and time?
about 3 years ago
Linux doesn’t store the time stamp for file creation. So you can’t get it from Linux.
Alternately if you are the one who is creating the file using a script or something, you can store the time stamp and file name in a separate file.
about 2 years ago
hi..do you know if theres a script i can run that can do this on a folder full of jpg’s?
about 2 years ago
That is straight forward. Just move to the directory which contains all jpg files and then use *.jpg instead of face.jpg
If you want to search recursively for all JPG files in a directory and this operation, you can try following examples:
find . -iname \*.jpg | xargs touch
find . -iname \*.jpg | xargs touch -d '1 Jan 2000 00:01'
find . -iname \*.jpg | xargs touch -d '31 Dec 2001'
find . -iname \*.jpg | xargs touch -d '11:59:59'
Hope this helps you!
about 1 year ago
Great articles and it’s so helpful. I want to add your blog into my rss reader but I can’t find the rss address. Would you please send your address to my email? Thanks a lot!