Mailinglist Archive: opensuse (1264 mails)

< Previous Next >
Re: [opensuse] Quick question: how to call a script function from "find"?
  • From: Vojtěch Zeisek <vojtech.zeisek@xxxxxxxxxxxx>
  • Date: Wed, 14 Jun 2017 12:44:54 +0200
  • Message-id: <3195122.U1DboVEYCx@tilia>
Dne středa 14. června 2017 12:09:43 CEST, Carlos E. R. napsal(a):
On 2017-06-14 08:12, Vojtěch Zeisek wrote:
Dne úterý 13. června 2017 23:38:24 CEST, Carlos E. R. napsal(a):
find /home/cer/Fusion/Videos/ -type d | parallel "sudo... && chmod...
&&..." This is my favorite style. :-)

I have to investigate that parallel command, but in this case I need the
commands to be sequential.

Sequential? Why do You need to process the files one-by-one? Construction
parallel "sudo chown cer:cer '{}' && chmod u+r+w+x,g+w+x,o+r-w-x,+t '{}'
&& sudo chown cer-g:cer '{}' && ..."
is of course sequential (because of '&&'). Or am I missing some point?


I mean I have to do on each file the three commands in that sequence (it
is done as user 'cer'). The chmod command will fail unless the directory
is owned by 'cer'.

Yes, my example above does so.

Yes, of course all files can be done all at once, but that is i/o bound,
not cpu bound, I think.

Not all, according to number of CPU threads (or less, see below).

But then I understood wrongly what parallel does. What it does is fire
several different threads, one per found file (directory in this case).
Up to... how many, as many as CPUs available?

Let's say 'find' lists 100 files (items/directories/whatever) and You have 4
CPU threads (unless You say e.g. '-j 3' to use only three of them). Then,
parallel is going to process 4 files in the same time, so Your task will be
done ~4 times faster than when using 'find ... -exec ...' or some loop
(disregard possible limitation because of RAM or slow HDD). It starts to
process first four files provided by 'find' and when first of them is done, it
starts to process another one. So all the time until all input files are
processed it keeps all CPU threads busy - all the time processing four files.
Is this clear now? :-)
And construction of 'parallel "c1 && c2 && c3"' is actually same as the 'find'
or 'while' loop do: GNU Parallel receives first four directories (in Your
case) and on each of them it sequentially launches commands 'c1 && c2 && c3'
in very same way as if You'd do it manually in command line. So I think it
does what You need. :-)

Vojtěch Zeisek
< Previous Next >