screen
in a terminal. Press Enter after reading the introductory text. Virtual terminals in Screen can be manipulated by pressing the Ctrl+A key combination, and subsequently pressing a key to execute one of the commands given below:
- c creates a new virtual console
- n switches to the next available virtual console
- p switches back to the previous virtual console
- " lists all available virtual consoles and their assigned numbers
- hitting a number key brings the corresponding virtual console to the foreground
- Esc lets you scroll back and forth in your terminal output
- d detatches the current screen sessions and brings you back to the normal terminal
When a Screen session is detached, the processes that were running inside it aren't stopped. You can re-attach a detached session by typing
screen -r
in a terminal.
First, create a session:
screen -S sessionname
It’s good to choose a descriptive session name. For example, before I switched to using Gmail I used mutt. So I would often start a session with the command “screen -S mutt” in one terminal window. If I went home, I could attach to that session from home, so I never needed to start-up or shutdown mutt.
You can easily have 10 interactive shells (numbered from 0 to 9) open in one terminal window. When you start a new session, you’ll be in shell 0. To create a new shell, hold down the “Control” key, press and release the ‘a’ key, and then type the letter ‘c’. I’ll write this as:
To create a new interactive shell, press Control-a c
Switching between shells is easy too.
To switch between shells, press Control-a # where # is the number of the shell. For example, to switch to shell number 1, press Control-a 1
Voilà! Now you can easily run 10 different shells in one terminal window! But what about if you want to go home and attach to a session from home? Use something like ssh to get on your work machine. Then here’s the command:
screen -d -R sessionname will resume a session that you started in a different location.
Technically this command is doing some special things. If you started the session somewhere else, the “-d” option will “detach” it at the other location, and “-R” will reattach your current terminal window to the session. If sessionname hasn’t been created, it will create the session for you. So the command above will migrate a session to your current window and disable the session at other locations. That’s usually what you want.
To exit a session, it’s easiest to exit all the shells in the session. If you want some more info on screen:
Control-a ? will give help inside of screen.
Typing “man screen” at a Linux command-line will show more help on screen.
There are web pages with moreinfo on screen.
- https://www.vultr.com/docs/using-screen-on-ubuntu-14-04