The most basic approach is with &
, this other answer is right. It also advocates nohup
but nohup
redirects stdin, stdout and stderr, something you may or may not want. Read Difference between nohup
, disown
and &
and make an educated decision.
Another approach is parallel
. It will be useful if commands you want to parallelize are similar to one another and you can craft a pattern.
Basic variant of the tool (from moreutils
, at least in Debian) allows you to limit the number of jobs that are run at the same time. GNU parallel
is more advanced. If jobs you want to run generate output then the following options will be particularly useful:
--group
Group output. Output from each job is grouped together and is only printed when the command is finished. Stdout (standard output) first followed by stderr (standard error). […]
(source)
(--group
is enabled by default, so usually you don't need to use it explicitly.)
--keep-order
-k
Keep sequence of output same as the order of input. Normally the output of a job will be printed as soon as the job completes. […] -k
only affects the order in which the output is printed - not the order in which jobs are run.
(source)
With them the output from multiple jobs will be organized, something you cannot get from &
. Sometimes you may not care about output but still care about sequence; like in this answer of mine where GNU parallel
is used to parallelize multiple curl
processes and get the exit status from each, retaining the sequence.
In Debian GNU parallel
is in a package named parallel
. As a separate executable parallel
can be run from any shell.
wait
command to wait for them to terminate. Other shells, such as Elvish have explicit support for parallelism. I think you need to rephrase your question to make what you're trying to do clearer for a reader of your question.