How to run multiple commands in Linux using screen command

You can use multiple commands in Linux using screen command. Here I using the window number, instead of the window name:

  1. create session
  2. screen -S SessionName -t 0 -A -d -m
  3. create second window
  4. screen -S SessionName -X screen -t 1
  5. send command to first window
  6. screen -S SessionName -p 0 -X stuff $'echo WinName0\necho cmd1\necho cmd2\n'
  7. send command to second window
  8. screen -S SessionName -p 1 -X stuff $'echo WinName0\necho cmd1\necho cmd2\n'
  9. now check if the command has been runned on the first window
  10. screen -R SessionName -p 0
  11. now check if the command has been runned on the second window
  12. screen -R SessionName -p 1

Tested with screen (CENTOS 7.x x64).

YouTube channel: https://www.youtube.com/@trainbrain007