If youâ€™ve ever used SSH to connect to a server, you â€˜ll know its limitations: if you want to open a new window, youâ€™ll need to create a second SSH connection to the server. And if the connection breaks during the SSH tunnel, youâ€™ve lost your progress. This is where Screen comes in.
Screen, which calls itself a â€œfull-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).â€ is a usefull tool to use 1 SSH connection, but use multiple screens to work in. So you can have 1 screen to write some scripts in, another to tail a logfile and a third to check your IRC messages
Screen is installed by default on most installations, you can verify this by running the â€œwhich screenâ€ command. If itâ€™s not installed, try to apt-get or yum it – itâ€™s in most repositories.
You can start screen by typing:
[root@whosyourdaddy ~]# screen
This makes sense, right?
Youâ€™ll probably notice that not much happens if you type that. At least, it seems like not much as happened. In fact, youâ€™ve just opened a new â€œscreenâ€ to type your commands. The program â€œscreenâ€ has a few commands of its own, in order to create a new window, and navigate through the open ones.
Once youâ€™ve opened â€œscreenâ€œ, you can see a command list by typing â€œCTRL + Aâ€, followed by â€œ?â€ (the question mark). By typing â€œCTRL + Aâ€ you state that the next signal is to be sent to the program â€œscreenâ€œ, in stead of to the Shell (like you would in a normal shell). Youâ€™ll see a list of all bindings known to â€œscreenâ€œ.
Start a new window by typing â€œCTRL + Aâ€ + â€œcâ€. The C stands for Create – I know, too obvious. A new window will be created. In order to test this, type the command â€œtopâ€. Then create a new window, by using â€œCTRL + Aâ€ + â€œcâ€. Youâ€™ll see top disappear, and a new window will open. Type in some commands of your choice, and return to the previous window, by doing â€œCTRL + Aâ€ + â€œnâ€. The â€œnâ€ stands for â€œNextâ€, and will open the next screen. â€œCTRL + Aâ€ + â€œpâ€ wouldâ€™ve opened the previous screen.
Closing a window, can be done by typing â€œexitâ€ (like you would in a normal shell). This will cause you to fall back to the previous monitor you opened, or to your main prompt – where you started screen, showing you a message such as â€œ[screen is terminating]â€ – so youâ€™ll know youâ€™ve hit the main shell.
The biggest advantage in using screen, is that you can â€œdetachâ€ a screen-session. This means you return to the normal shell, but the processes started in â€œscreenâ€ are still active in the background. You can detach yourself by typing â€œCTRL + Aâ€ + â€œdâ€. Again, obvious that â€œDâ€ stands for Detach. This gives you more flexibility for managing your server(s): you can start a number of processes, quietly exit the shell and return a couple of hours later to pick up the session started in screen.
Should you disconnect by accident, during a screen-session, you can always pick up a previous screen by relogging to shell and typing â€œscreen -lsâ€œ. This will show a list of all running screen-sessions at any given time. You can pick up a previous screen-session, by typing â€œscreen -r <name_of_session>â€œ.
Probably known to most Linux Administrators, but still an awesome tool.
Related Posts: On this day...
- Internet pornography destroying men's ability to perform with real women, finds study - 2011
- US President Obama just booked all 570 rooms at the Taj Mahal hotel - 2010
- Booklife: a guide to a sane and productive writerly life - 2009
- HOWTO: Host your very own Windows 7 torrenting party - 2009
- Driver of damaged car pretends nothing is wrong - 2008
- Online Poker World Rocked by Hack - 2007