0

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 {} \;

or

find . -type f -exec stat -c %n "{}" \; -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?

TJJ
  • 155
  • 10
  • 1
    I think it's a bug in toybox as it doesn't work with the newest binary, though it runs with busybox. – TJJ Mar 25 '19 at 18:43
  • It definitely is a bug. I reported it and it got already fixed. Unfortunately, this won't help me on Android until this version of toybox makes it into the firmware. – TJJ Mar 26 '19 at 15:29

1 Answers1

1

If toybox can't do multiple exec, there are alternatives.

In this particular case, you may be able to just use a single stat:

find . -type f -exec stat -c "$(echo -e "%n\n%y")" {} \;

# or just insert the newline verbatim in single quotes:
find . -type f -exec stat -c '%n
%y' {} \;

For running multiple commands (assuming paths don't contain newlines):

find . -type f -print | while IFS= read -r f; do
    stat -c $n "$f";
    stat -c %y "$f";
done
jhnc
  • 11,310
  • 1
  • 9
  • 26
  • Wow perfect! The first command did it! I tried to do it with a single stat command as well but couldn't figure out how to escape newline. I wanted to put that into the "-c " part, which didn't work. Your code snippet does it! Thx so much! – TJJ Mar 26 '19 at 15:32
  • 13 extra characters just to enter one newline :-) You could also just use single quotes and enter them verbatim. – jhnc Mar 26 '19 at 15:42
  • I found that newline doesn't work with single quotes. – TJJ Mar 26 '19 at 15:47
  • interesting. I guess your shell doesn't follow POSIX then (http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02 - section 2.2.2) – jhnc Mar 26 '19 at 15:57