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
, MFT
Entry Modified
time is very identical to UNIX's ctime
.
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...
Commented
Sep 20, 2020 at 20:28
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?
Commented
Sep 20, 2020 at 20:57
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.
Commented
Sep 20, 2020 at 22:28
touch -m ....
the files on the SDCARD no longer appears to work either. Definitely have some homework to do.
Commented
Sep 20, 2020 at 23:17
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 !