# run in background
{command to run} &
# run in background and write stdout and stderr to 'output.log' file
# 2 refers to the second file descriptor of the process, i.e. stderr.
# > means redirection.
# &1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.
# run command in background, output will also show in terminal
{command to run} 2>&1 > output.log &
# run command in background, output will NOT show in terminal
{command to run} > output.log 2>&1 &
# https://www.brianstorti.com/understanding-shell-script-idiom-redirect/
Run in background with Screen
# create screen name terraria
# ctrl+a+d to return to orgin terminal
# still running after ssh connect stopped
screen -S terraria
# ls all screen
screen -ls
# back to screen name terraria
screen -r terraria
# kill screen session by name
# screen -X -S [session # you want to kill] quit
screen -X -S terraria quit
./tModLoaderServer -config serverconfig.txt
# ./tModLoaderServer -config serverconfig.txt 2>&1 > output.log &
# ctrl+a+d to return to orgin terminal
# kill all detached session
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
# kill all dead(unreachable) session
screen -wipe