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.




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


RELATED CONTENT
AIX, IBM pSeries server administration
Unix admin tutorial: How much memory is in this machine?
How to use Unix file system snapshots
The Unix year 2038 problem
Analyst group touts Unix OS scorecard
What are the top skills for systems administrators?
Comparing Unix operating system vulnerabilities
IBM AIX 6, Power6 blade due out this month
Platform choices: Is Unix a legacy platform?
IBM hikes licensing price on faster Power6 processors
IBM AIX 6 virtualization catches up to Sun Solaris, HP-UX

HP Integrity server, Itanium servers and HP-UX
IBM buys former adversary and mainframe startup PSI
Unix admin tutorial: How much memory is in this machine?
How to use Unix file system snapshots
The Unix year 2038 problem
Analyst group touts Unix OS scorecard
HP-UX gets yet another update with HP-UX 11i v3
What are the top skills for systems administrators?
IBM virtualizes Linux on new System p Power6 servers
Comparing Unix operating system vulnerabilities
HP-UX nPars gets more flexible, but is it enough?

Sun Solaris Unix and Sparc server platforms
New Sun/Fujitsu servers boast quad-core Sparc64 chip
Serial computing is dead; the future is parallelism
Unix admin tutorial: How much memory is in this machine?
Solaris system performance tuning
Sun has deepened PostgreSQL/Solaris integration, says university
How to use Unix file system snapshots
The Unix year 2038 problem
Analyst group touts Unix OS scorecard
Sun, Fujitsu pack 16 cores into 1U Sparc server
What are the top skills for systems administrators?

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.

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

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




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