Execute multiple programs and redirect their outputs (Linux)

Recently, I had a situation where I needed to execute multiple programs in Linux at the same time while redirecting their outputs to separated log files and wait for them to finish.

If you ever need to do something like that, I leave year the script that I used to accomplish that task:


# Add the full path processes to run to the array
PROCESSES_TO_RUN=("/home/joao/Code/test/prog_1/prog1" \
# You can keep adding processes to the array...

for i in ${PROCESSES_TO_RUN[@]}; do
    ${i%/*}/./${i##*/} > ${i}.log 2>&1 &
    # ${i%/*} -> Get folder name until the /
    # ${i##*/} -> Get the filename after the /

# Wait for the processes to finish


  • Courtney Campbell

    You should checkout gnu parallel.

    • Thanks for the suggestion. I will differently check it out 😉