How do I change the modified date of a file, specifically PNGs, on Android without root?
Total Commander failed to do it with a permission error Access Denied.
How do I change the modified date of a file, specifically PNGs, on Android without root?
Total Commander failed to do it with a permission error Access Denied.
SHORT ANSWER:
You can simply touch the file or provide any time and date in past or future:
~$ touch /sdcard/test_file
~# debugfs -R 'stat media/0/test_file' /dev/block/bootdevice/by-name/userdata | grep crtime:
crtime: 0x5c926e0d:2d61b810 -- Wed Mar 20 21:45:01 2019
~$ touch -d '2009-2-13 14:32:55' /sdcard/test_file
~$ stat /sdcard/test_file
[...]
Access: 2009-02-13 14:32:55.000000000 +0000
Modify: 2009-02-13 14:32:55.000000000 +0000
Change: 2019-03-20 21:45:38.067021025 +0000
Birth: -
Some file explorers like MiXplorer also have options to change Modified Time.
You don't need super user privileges to change mtime. Only the file should be writeable by your user ID (app in case of Android).
DETAILS:
touch uses utimensat to update time of access (atime) and modification (mtime) provided that filesystem supports the timestamps be saved in inode along with file's data.
Birth/creation time (btime/crtime) - a part of extended file status which requires at least 256bytes inode size - is not standardized, thus rarely supported by filesystems. In above commands debugfs is used with root privileges to get creation time of file on ext4 because some stat binaries aren't updated to use statx yet (requires at least Linux Kernel 4.11), so btime is empty.
Both btime and change time (ctime; inode/metadata modification time) are supposed to be handled by system, not simply changeable by user.
Since Android is based on Linux, it inherits the concept of inode and timestamps from UNIX world. Common Linux filesystems like ext4 and f2fs support timestamps, including the emulated filesystems used by Android on SD cards. Other OS and filesystems have similar concept with slightly different terminologies. E.g. on Windows' NTFS, MFTEntry Modified time is very identical to UNIX's ctime.
Total Commander - file system - mark one or more files - long touch - properties - change the displayed date to what you need (there is also a "Now" button) - Save - voila !
BTW Total Commander is an excellent tool - in all areas and on all platforms !
touch -mwasn't working for me today where android phone is mounted using SSHFS on Ubuntu 16.04.6. However files copied to the phone OK. Most puzzling... – WinEunuuchs2Unix Sep 20 '20 at 20:28touch -deven if you are not the file owner (since all files in/sdcardare owned by root). On normal *NIX filesystemsutimensat/utimeshave strict permission requirements. Btw did you mount/sdcardor/data/media/0on SSHFS? – Irfan Latif Sep 20 '20 at 20:57echo rick | sshfs -o auto_cache,reconnect,defer_permissions -o Ciphers=aes128-ctr -o Compression=no -o password_stdin -p 2222 rick@192.168.0.11:/ /mnt/phoneFile server mount is different defaulting to port 22 and not nearly as complicated. – WinEunuuchs2Unix Sep 20 '20 at 22:28touch -m ....the files on the SDCARD no longer appears to work either. Definitely have some homework to do. – WinEunuuchs2Unix Sep 20 '20 at 23:17/sdcardand the actual one/data/media/0)? Did you try on device too (e.g. through Termux oradb shell) on both paths? If the problem is only with emulated path, is it FUSE orsdcardfs? Did you try with root privileges too? Does the bug occur without-m -dtoo i.e. when changing bothatime/mtimeto current time? Can you sharestraceof failed command to figure out what syscall fails with exactly what error? Thanks. – Irfan Latif Sep 21 '20 at 07:17-m -d. Only using SD Card with fusermount. As I said it can write files no poblem. Untarring a file doesn't honor modification time, it gets curretn time. I tried access time and creation time as well. – WinEunuuchs2Unix Sep 21 '20 at 11:30cp --preserve=timestampsis not honored.touchis not honored. The Android OS is simply broken when it comes to modification times. – WinEunuuchs2Unix Sep 21 '20 at 11:53