Screen
January 19th, 2010
I love when I find useful built-in commands that I never knew about. When starting out with Linux, I heard about the typical heavy hitters like grep, sed, and awk. Then I discovered some variations on common commands, such as htop and less. And then every so often, someone mentions a command in passing that causes me to say “Wait… what is that?”
Screen is one of those sorts of tools. I was watching a VNC demo of one of our team’s sprint reviews and was distracted by the fact that he had a tab bar on the bottom of a terminal. It turns out that was just part of the coolness of “screen”.
Screen is basically a window manager that runs in a terminal, letting multiple shells run within the single terminal. I’m sure there are other features that I’d find awesome, but there are two that immediately stood out.
As I mentioned, screen allows you to run multiple shells inside of a single terminal. Instead of starting up a handful of separate SSH sessions to a server, I now just use screen to manage multiple shells inside of a single connection. Each call to screen creates a new shell, with a simple emacs-like syntax to switch between them:
ctrl + a + n # next ctrl + a + p # previous ctrl + a + 0 # select screen 0
One side note on this, by default the tab bar displaying the running shells isn’t displayed. Adding the following to ~/.screenrc enables a visual indicator of the current and possible shells that are open:
hardstatus on
hardstatus alwayslastline "%{-b gk}%-w%{+b kg}%50>%n %t%{-b gk}%+w%< %= %{w}%D %M %d %C%a"
While useful, it can still get a little confusing when a bunch of shells are opened. The title can be set by:
ctrl + a A

The second major piece of awesomeness is the ability to detach from a running screen and reattach later. Going back to the SSH example, this lets me leave some shells running, detach, completely disconnect from the server, and then reattach to the screen later (with everything left exactly as it was).
Again, an emacs-like syntax for detaching from a running screen:
ctrl + a + d
Later, to reattach to the running screen detached from earlier:
screen -dr
Like I said, I’m not trying to make this post sound like I’ve discovered some hidden black magic in Linux. It’s just an attempt to let new users know about this awesomeness.


etank
January 19th, 2010 at 10:38 am
Nice find there. I use screen every day but mostly on an ubuntu system. On my fedora systems I miss the byobu app that is in ubuntu that makes adding to the screen session very easy.
Jason Dobies: Screen | TuxWire : The Linux Blog
January 19th, 2010 at 12:09 pm
[...] here: Jason Dobies: Screen Share and [...]
tk009
January 19th, 2010 at 12:23 pm
Screen is a great program and must have if you spend any amount of time in the CLI. I ‘discovered’ it when i started using irssi for IRC and now use it as a command-line desktop of sorts.
dgoodwin
January 19th, 2010 at 11:48 pm
Screen FTW! This reminds me I should probably learn how to use sed/awk.