Search code examples
androidlinuxshelltoybox

find: combining multiple "-exec" statements not working with toybox / Android?


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?


Solution

  • 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