Home > Data Center Tips > > How to use GNU screen: Sys admin tutorial
Data Center Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 


How to use GNU screen: Sys admin tutorial


Bill Bradford, Contributor
03.27.2008
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Most system administrators I know carry a pocket multi-tool of some sort. The free software equivalent of that tool is a program called GNU Screen.

According to its website, GNU Screen (referred to as "screen") is "a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells." In short, you can have multiple terminal sessions running in a single window or serial console session without needing a graphical user interface (GUI).

Screen is included with most modern Linux distributions and Mac OS X, and binary packages are available for Solaris, AIX, HP-UX and IRIX. For most any other UNIX-like systems, source code can be downloaded from the Free Software Foundation.

Once screen (and its associated termcap entries -- see the Install file if you're compiling from source) is installed, run it from a command prompt:

$ screen

Version information and GNU GPL copyright notice will be displayed along with a prompt to press the space bar or return key. Do so and the screen will clear, giving a command prompt back. Screen has now taken over and your interactive shell session is now running "inside of" it.

Screen's most useful feature is terminal multiplexing. To demonstrate, start editing a file with your choice of text editors. When the session is up and you have a screen full of text, press CTRL-a and then c. This will create a second terminal session in the same window, clearing the screen and displaying another shell prompt. However, your original editor session is not gone! Press CTRL-a twice to switch back to the editor session from your second virtual screen.

To start additional screens, just press CTRL-a (which is screen's command key) and then c (for create). Once you have created more than two screens, you can't just flip back and forth between them by pressing CTRL-a twice; you'll have to press CTRL-a once and then the number of the screen you want to switch to (starting with 0 for the first screen, 1 for the second, and so on). If you forget where you are, pressing CTRL-a and " will give you an organized list of screens. Pressing CTRL-a and A will let you rename a screen from the default (normally the name of your shell) to something more useful. For instance, I use "email", "chat" and "usenet". CTRL-a and k will kill a specific terminal session once you're done.

The second most useful feature of screen is the ability to de/re-attach a multiplexed terminal session. Normally, disconnecting from an SSH or telnet shell session, killing an xterm window, or logging out from a serial console will cause you to lose whatever you are working on. Screen solves that problem by allowing you to put your entire session into the background, log out and then come back to that same session later with no data lost. To demonstrate, start screen and an editor session as in the prior example, then press CTRL-a and then d (for detach). A message will appear stating that your session has been detached, and your non-screen command prompt will return.

[detached]
$

Your screen session is now running in the background. You can now kill your shell session or log out of the system. To retrieve your screen session, log back in or open another terminal window and tell screen to reattach what you were working on:

$ screen -r

Your previously detached screen session should pop back up, complete with text editor. This is useful if you have to switch terminals during a work day or work remotely and don't want to lose your work due to a flaky connection. If your controlling terminal disappears while running screen, the session will automatically detach so that you can log in and reattach it without losing data. Multiple screen sessions can be detached in the background; running screen –r without specifying a session will get you a list and instructions on how to reattach to a specific session.

$ screen –r
There are several suitable screens on:
584.pts-1.machine (Detached)
20694.pts-33.machine (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

This short tutorial has barely scratched the surface of the many capabilities of GNU Screen. Other features include:

  • Session logging to a text file or hard-copy printer
  • Cut and paste between virtual screens
  • Split-screen windows in the same display
  • Screen session sharing between multiple connections
  • Screen locking and password protection

To get a full list of screen commands and keybindings, press CTRL-a and ? (question mark).

More information is available from the manual page. To read it run man screen.

GNU Screen has been part of my sys admin toolkit for the past 12 years -- you should make it part of yours.

ABOUT THE AUTHOR: Bill Bradford is the creator and maintainer of SunHELP and lives in Houston, Texas, with his wife Amy.

Rate this Tip
To rate tips, you must be a member of SearchDataCenter.com.
Register now to start rating these tips. Log in if you are already a member.




BROWSE BY TAG
AIX, IBM pSeries server administration,   Server hardware,   Unix operating systems and servers,   HP Integrity server, Itanium servers and HP-UX,   Sun Solaris Unix and Sparc server platforms,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
AIX, IBM pSeries server administration
Unix updates are slower, and users like it that way
IT pros pooh-pooh latest monopoly claims against IBM
IBM VMworld news in brief
IBM announces Power7 upgrade path in uncertain Unix market
Comparing Unix versions: AIX, HP-UX and Solaris
Top 50 universal Unix commands
IBM doubles refund for Sparc migrations: News in brief
Sun shops prefer Oracle to IBM, but worries persist
Uncertain future for Sun Microsystems overshadows new products
IBM withdraws from deal to purchase Sun; Dallas colo investigated

HP Integrity server, Itanium servers and HP-UX
Unix updates are slower, and users like it that way
Comparing Unix versions: AIX, HP-UX and Solaris
Itanium processor delays put HP's plans in question
Top 50 universal Unix commands
IBM doubles refund for Sparc migrations: News in brief
HP's Bladesystem Matrix to challenge Cisco's Unified Computing System
Reports of IBM, Sun buyout roil data center waters
IBM mainframe migration boosts OLTP, batch processing
IBM buys former adversary and mainframe startup PSI
Unix admin tutorial: How much memory is in this machine?

Sun Solaris Unix and Sparc server platforms
Unix updates are slower, and users like it that way
New eBay data center director dishes
How should Sun customers read Oracle's latest rumblings?
With Exadata, Oracle embraces Sun hardware
Solaris Project Crossbow offers virtualized network management
IBM announces Power7 upgrade path in uncertain Unix market
Roadmap for Sun Microsystems customers after the Oracle acquisition
Comparing Unix versions: AIX, HP-UX and Solaris
What does the future hold for Oracle's virtualization acquisitions?
Predicting Oracle's plan for Sun assets, the future for Sun customers

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



White Papers - Data Center Networking

The Intel IT Technology Center - Power, Performance and Mobility Solutions

HomeNewsTopicsITKnowledge ExchangeTipsBlogsMultimediaWhite PapersEvents
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts