How To Run Multiple Applications In A Single Terminal Window

Why clutter up your desktop with separate terminal windows for every task? Learn to love GNU screen, the terminal multiplexer, which essentially adds "tabs" to your terminal window. Here's how to use it, and tweak it to be even better.

Screen allows you to run multiple console applications within a single terminal window, and switch between them easily with the keyboard—but it gets even better: it also allows you to save your running session and come back to it later. So, for instance, you can remotely login to another PC over SSH, open up a screen session, and keep your applications running there in a screen session even after you disconnect.

Using Screen Shortcuts

Once you've installed screen and started a new screen session by simply typing screen at the terminal prompt, you'll need to know how to use a couple of simple commands, all of which are preceded by the Ctrl+A key combination. So, for example, to create a new "window" within screen, you'd press Ctrl+A, and then press C.

Here's a list of the most useful commands that you might need to use—you should enter these in lower case, they are simply shown here in upper case to make it more readable.

  • Create New Screen: Ctrl+A, C
  • Switch to Screen: Ctrl+A, N (where N is the number of the screen)
  • Switch to Next Screen: Ctrl+A, A
  • View List of Screen: Ctrl+A, W
  • View Screen Picker: Ctrl+A, " (double quote)
  • Detach Current Session: Ctrl+A, Ctrl+D
  • Attach to Running Screen Session: screen -R
  • Show Shortcut Keys: Ctrl+A, ?

There's loads of other commands that you can use to control your screen session, most of which can be accessed by typing Ctrl+A, ? at the prompt, which will bring up a help window that shows you all of the available bindings:

Adding a Hard Status Line to Screen

By default, screen doesn't show you anything about what terminal window you're using, or anything else about your PC—you have to switch back and forth between terminals with the Ctrl+A key combination or use the Ctrl+A, Ctrl+W key combination to see the list of terminals.

Simply create a new file at ~/.screenrc and add in the following text, which can be customised to fit whatever you'd like:

hardstatus alwayslastline

hardstatus string '%{= kG}[ %{G}%l %{G}%H %{g}] [%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}] [%{B}%Y-%m-%d %{W}%c %{g}] '

screen -t sh1 1

screen -t sh2 2

screen -t sh3 3

screen -t phperr 4 tail -f /var/log/dev/php_error.log

startup_message off

msgwait 1

Once you've created this file, exited and opened up a new screen session again, you'll see a line similar to this at the bottom of the screen, which will show you what session you're on, and some other system information as well:

If you'd like to know more about screen, including how to customise it with configuration directives, you can check out this excellent tutorial or just type man screen at the terminal prompt.

You can use screen on any platform, including Windows with Cygwin—you'll have to manually search and install it through the Cygwin installer, because it's not usually selected by default. Under Windows, you will lose some of the disconnect and reconnect ability, and some applications like the MySQL client won't function in a screen window, but it will work quite well otherwise.


    Also try tmux.

    I've had screen die with large column counts.

    Why keep multiple terminals open? So you can see multiple things happening side by side. e.g. crafting a command line on one, with the man page open on another.

    Screen really does rock, however, when you have a flaky net connection (as happened to be last year working in Indonesia). I you lose the connection, ssh back in, then 'screen -R'. Back to where you were.

Join the discussion!