Use screen to create a virtual terminal in Linux
Takeaway: Vincent Danen illustrates how the Linux tool screen can help you create virtual terminals.
Remote administration with SSH is something every sysadmin is familiar with. Likewise, doing multiple things at the same time, including lengthy compiles or long tasks is also something many of us are familiar with. Freeing up a console usually involves opening a new terminal and initiating a new SSH connection to get further work done, or—if observation of a task isn't critical—you can send the task to the background to free up the terminal.
Another solution exists in the form of the screen tool, a program that is included with every Linux distribution. Screen creates virtual terminals that you can control and interact with via one terminal. What's even better, a screen session can be disconnected without killing a running task. Imagine starting a long compile on a remote server and the connection dies; when the connection dies, so does your task. Screen works around this by allowing you to detach from a running session, log out, and resume it later, even from a different location.
To get started, make sure the screen package is installed using your distribution's package manager and then type:
$ screen
This will start screen and open a new session. To disconnect from a session, type CTRL-A then d. You will return to the prompt from which you issued screen, but everything you have done in screen is still available. If only one screen session is running you can reconnect to it using:
$ screen -R
If there are multiple screen sessions running, this won't work; but you can view a list of running screen sessions by using:
$ screen -list
There are screens on:
13995.pts-0.host (Detached)
14529.pts-0.host (Attached)
2 Sockets in /home/joe/tmp.
Here, you can see there are two sessions running. To connect to the detached session from a different location, you would use (after SSH-ing to that machine, of course):
$ screen -r 13995
where 13995 is the process ID of the screen session you wish to attach to.
There is a lot of help available for screen, and a lot of things you can do with it. You can view the screen manpage, the output of screen --help, and within a screen session, type CTRL-A then ? to get a list of commands you can use when in command mode (invoked by CTRL-A).
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!
Print/View all Posts Comments on this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SponsoredWhite Papers, Webcasts, and Downloads
- Voice over IP Reliability: Architecture Matters ShoreTel
- Streamline IT Operations and Drive Innovation Across Your Company SAP
- Improving Decision Making Through Enterprise Information Management SAP
- Strategies for Centralizing Data Backup Riverbed
- Voice over IP and Productivity: How IP Telephony Enables Experts and Support Staff to Be Seemingly Everywhere at Once ShoreTel
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET
