0

I did a loop process using Bash for command, on Linux mint, with the input range is from previous process comes from find, but it'd apparently and clearly did it in batch process relative to terminal output, rather than the immediate one if find range is explicit and performed to give a terminal output. mine is;

IFS=$'\n'
for s in $(find ~+ -type f -regextype posix-extended -iregex ".*/data\.(tmp|bak)" -printf '%p\n')
    {
    echo $s
    }

it'll be still without any output for 100 sec. or more, rather than straightly shows some on terminal. How to make it work as nearly fast as find instructed alone and directly ? thanks inadvance, I appreciate it.

1 Answers1

0

A for loop iterates over a static list, always. So the body of the loop in your question will not start executing until the items that it will iterate over are completely specified. These will not be completely specified until the find command has finished executing.

There are several issues with your command, and most are addressed by the question "Why is looping over find's output bad practice?".

In general, it's better to have find act as a pathname generator for an internal script:

find ~+ -type f \( -iname data.tmp -o -iname data.bak \) -exec sh -c '
    for pathname do
        # process "$pathname" here
    done' sh {} +

This way, you don't need to care about how the pathnames that find gives to the loop are delimited (this will gracefully handle pathnames containing spaces and newlines etc.)

Related:

Kusalananda
  • 333,661
  • -exec ... {} + will still of course batch, but it might depend on the implementation how much it does. On Linux, GNU find seems to batch up to a command line length of 128 kB, even though the actual limit is higher. – ilkkachu Sep 22 '18 at 10:51
  • @ilkkachu Yes, it will batch, and the original command in the question (if the syntax was corrected) would not batch but wait until the full command had finished. – Kusalananda Sep 22 '18 at 11:15