Neil Bothwick lives and breathes Linux and open source.
Q
It’s a date
What is the correct command-line terminal command for changing the date attribute of any file? Not to be confused with the date modified or date created attribute of a file. If it is not possible using the terminal, does an open source app exist that can accomplish such a date attribute file change?
Owen Nash
A There are several date attributes associated with a file in the ext4 filesystem: date created, date modified, date changed and date accessed. There are also date attributes stored in the EXIF data of image files – usually from digital cameras. The difference between date modified and date changed is that the former is set when the file’s contents are modified, whereas the latter refers to when the file’s metadata or attributes – such as permissions, owner, or name – are changed. To view all of these timestamps, use the stat command: $ stat filename
You can change these with touch. At its simplest, this changes the modified and changed timestamps to the current time: $ touch filename
Use -m if you only wish to change the modified time. There is no option to alter changed time, but you could rename the file and then name it back – or set and unset a permission.
There are other options with touch: -t sets the time to a given time, while -r takes another file and uses the timestamps from that.
If you are referring to the EXIF data stored within files, such as photographs, the approach is different. This data is usually visible in image viewer programs but they are not normally capable of editing it. There are two common ways to do this. Our preferred option is to use exiftool on the command line. The following command displays all the data stored in the image: $ exiftool filename