'Linux - modify file modify/access/change time [closed]
I read an article about new steganographic method: "Time is on my side: Steganography in filesystem metadata" http://www.sciencedirect.com/science/article/pii/S1742287616300433. It is very interesting and makes me thinking about one thing.
Is it possible to manipulate file modify/access/change time metedata using C or any other language in Linux OS? I found method which is using touch command, but it creates file with specific tag value. I would like to find way to modify this metadata in existing one.
Solution 1:[1]
Using touch command you can edit time metadata of files. Example:
touch -a -t 201611161200.10 file.txt
It will result in modifing access timestamp, and replace it with date 2016-11-16 12:00:10.000000000 To change 'Modify' date you should use flag -m
Solution 2:[2]
I came across this thread and I had to share my findings (as mentioned this site is a repository for knowledge):
"touch" is a command line application and in order to execute it (from c++ application) you need to run system() which is discouraged. more on touch: http://www.linfo.org/touch.html
The programmatic way to set the access and modification timestamps of a file is using one of the following system calls: utime, utimes, futimes, futimens (simple internet search will give you the man page of them) i.e http://www.tin.org/bin/man.cgi?section=2&topic=utimensat
Linux has 3 time stamps associated to a file:
- Access - the last time the file was read
- Modify - the last time the file was modified (content has been modified)
- Change - the last time meta data of the file was changed (e.g. permissions) extra reading here: https://unix.stackexchange.com/questions/2464/timestamp-modification-time-and-created-time-of-a-file/2465#2465?newreg=b4e0ee2ef0734b8792240c205e420c55
It's relatively easy to modify the 'access' and 'modify' timestamps using the above commands, but modifying the change timestamp (last time permissions were changed) is harder. Thread on this here: Setting creation or change timestamps
Solution 3:[3]
touch -c -m --date="2022-02-19 10:00" /path/to/your/file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Krystian |
| Solution 2 | Community |
| Solution 3 | keikai |
