Ubuntu – How to run multiple commands in parallel and see output from both

command line

Specifically, I want to run

lsyncd lsyncd.lua

And

webpack --progress --color -w

Which are both long-running processes. I want to see the output from both, interlaced in my terminal. It doesn't matter if the results are a bit jumbled, I just like to see that they're doing what they're supposed to.

Also, I want it to kill both processes when I press Ctrl+C.


I'm trying

parallel ::: 'lsyncd lsyncd.lua' 'webpack --progress --color -w'

which seems to be working, but I can't see any output even though when I run those commands individually, they output something.

Best Answer

Using parallel (in the moreutils package):

parallel -j 2 -- 'lsyncd lsyncd.lua' 'webpack --progress --color -w'

Since the parallel process runs in the foreground, hitting CTRL+C will terminate all the processes running on top of it at once.

  • -j: Use to limit the number of jobs that are run at the same time;
  • --: separates the options from the commands.
% parallel -j 2 -- 'while true; do echo foo; sleep 1; done' 'while true; do echo bar; sleep 1; done'
bar
foo
bar
foo
bar
foo
^C
%
Related Question