8

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.

Reddy Lutonadio
  • 7,164
  • 2
  • 17
  • 49
Bernard
  • 181
  • 1
  • 1
  • 4

2 Answers2

7

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.

Irfan Latif
  • 20,353
  • 3
  • 70
  • 213
  • touch -m wasn'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:28
  • @WinEunuuchs2Unix that must be due to your SSHFS permissions (FUSE mount options). Android's emulated filesystem is quite tolerant. It even allows touch -d even if you are not the file owner (since all files in /sdcard are owned by root). On normal *NIX filesystems utimensat/utimes have strict permission requirements. Btw did you mount /sdcard or /data/media/0 on SSHFS? – Irfan Latif Sep 20 '20 at 20:57
  • This is most embarassing. Touch does work manually just not within my python program when file server touches phone. Touch phone to file server works. Grr three times I've run this two hour update over WiFi. Back to the drawing board. My Mount is: echo rick | sshfs -o auto_cache,reconnect,defer_permissions -o Ciphers=aes128-ctr -o Compression=no -o password_stdin -p 2222 [email protected]:/ /mnt/phone File server mount is different defaulting to port 22 and not nearly as complicated. – WinEunuuchs2Unix Sep 20 '20 at 22:28
  • I spoke too soon. Manually touch -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
  • It appears it's a bug in Android where you can't set the modification time. Not just my version 6 but even version 8:https://freefilesync.org/forum/viewtopic.php?t=4311 The only option is to root the phone but I'm going to change my program instead to not sync to Android devices based on modification time. Such a shame a Linux system got crippled by Google in this fashion. – WinEunuuchs2Unix Sep 21 '20 at 01:06
  • @WinEunuuchs2Unix interesting find. I've a few queries now. Did you try both paths (the emulated one /sdcard and the actual one /data/media/0)? Did you try on device too (e.g. through Termux or adb shell) on both paths? If the problem is only with emulated path, is it FUSE or sdcardfs? Did you try with root privileges too? Does the bug occur without -m -d too i.e. when changing both atime/mtime to current time? Can you share strace of failed command to figure out what syscall fails with exactly what error? Thanks. – Irfan Latif Sep 21 '20 at 07:17
  • I've actually moved on and created a file shadow system with the correct modification time. Other errors reported here: https://issuetracker.google.com/issues/36930892 I tried root. I tried -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:30
  • BTW the phone is not plugged into my laptop or file server for that matter. It is running SSH Open Server (provided by Banana Studio) over WiFi. There is no /data/media directory or /run/gvfs (whatever) directory. It is mounted as if it were a normal drive like ext4 or NTFS or what have you. As I said I can copy a file to it and it gets current time. cp --preserve=timestamps is not honored. touch is not honored. The Android OS is simply broken when it comes to modification times. – WinEunuuchs2Unix Sep 21 '20 at 11:53
1

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 !

Meiki67
  • 11
  • 1