3

I am trying to figure this out on an Android phone running Oreo / 8.0, with toybox 0.7.3-android.

I am trying to get a list of files inside a folder and their respective mtime. I am running this command:

find . -type f -exec stat -c %n {} \; -exec stat -c %Y {} \; -exec stat -c %y {} \;

or

find . -type f -exec stat -c %n "{}" \; -exec stat -c %Y "{}" \; -exec stat -c %y "{}" \;

In both cases I am only getting the result from the first invocation of "stat". Am I overseeing something or is this the way toybox works on Android?

The output file should look like this:

./file1.txt
1553516120
201903251315.20
./file2.txt
1549678694
201902090318.14
./file3.txt
1553541066
201903252011.06
./file4.txt
1553515882
201903251311.22
./file5.txt
1585138731
202003251318.51

EDIT: This is apparently a bug in toybox. I reported it and the working fix is currently awaiting to be merged into the source code of toybox.

2
  • Without knowing more about what you're trying to do, could you simply use ls? Something like: ls -ld /path/to/directory --full-time | grep '^d'. This will filter out directories and show the full timestamp of files in the specified path.
    – CzarMatt
    Mar 25 '19 at 19:00
  • I am trying to backup the file timestamps using a script. Thx for your idea, unfortunately "--full-time" is not a recognized switch.
    – TJJ
    Mar 25 '19 at 19:10
0

This should work:

find . -type f | xargs -I {} stat --printf='%n \n %Y \n %y \n\n' '{}'

But Android's limited toybox stat doesn't support --printf formatting. So either use stat binary with full options e.g. from Termux or statically built, or you need to do one step extra:

find . -type f | xargs -I {} stat -c '%n--%Y--%y--' '{}' | sed 's/--/\n /g'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.