Screen command

It’s a new command I learned this week. Why don’t I meet this command in last 8 years?

Usage from cheat screen.

# To start a new named screen session:
screen -S <session-name>

# To detach from the current session:
Press Ctrl+A then press d

# To re-attach a detached session:
screen -r <session-name>

# To list all screen sessions:
screen -ls

# To quit a session:
screen -XS <session-name> quit

Sometimes a non stop command is executed and a new terminal window has to be open to type other commands. With screen, we can create a session to run the command and then detach, and do some other things and then attach to go back to the session. No need more windows.

For example, create a session named yarn and then watch build by yarn dev and then detach to do something else. Finally go back to see what the log is. Quite helpful, right?

1. screen -S yarn
2. yarn dev
3. ctrl-A D
4. do something...
5. screen -r yarn