Using the screen command under Linux is an effective way of having several "windows" to work in. One screen may be the bash shell, another mysql command line open against a database and yet another a vim session for editing source code files.

Under Windows one can use alt-tab to fast change focus to another window. Under Linux I may have to:

  1. Type Ctrl-a + "d" (to detach the current screen)
  2. Type "screen -ls" to see pid's for active screens (assuming that I don't remember the pid of the other screen)
  3. Type "screen -r [pid]" (to resume the selected screen)

Now, normally using command line can be fast once the proper commands and shortcuts have been acquired. However, changing between screens does not seem elegant and fast compared to just pressing Alt-tab in Windows. In fact, it seems extensive, clumsy and tedious having to type out commands and pid's.

(Point 3 above can be improved a bit by typing "scr" + Ctrl-r to go back through command history, assuming that I have accessed the other screen earlier, but it is still not really elegant)

So, I wonder if there is a way to fast change between the screens with a single or few key strokes -- preferably one that does not require to be set up again every time one starts a new terminal session against the server.

Update: As Mr Lister points out, the terminal application in Linux desktops (and even putty in Windows) in and of themselves provide an option to open several consoles and switch between them with short cuts, e.g. Ctrl+PgUp/Dn in Ubuntu. However, in this case I am using the basic bash terminal in a headless server in the cloud, so the accepted solution is a perfect one in the sense that the functionality described resides in bash in the server itself and does not depend on opening additional connections to the server.

  • I know you have your answer, so that's good. But in order to make this a better question (foir future reference by other people) you should mention what kind of Linux and what kind of desktop you're running. – Mr Lister Jul 3 '16 at 11:29
  • For example, on my system, I can press Alt+Tab to switch between windows, just like in Windows, and also Ctrl+Alt+F(n) to switch between consoles, so I'm guessing you don't have the same setup I have! – Mr Lister Jul 3 '16 at 11:31
  • @MrLister: I run an Ubuntu Linux with terminal as the base and inside that I can open several consoles and change between them with Ctrl-PgUp/Dn. However, I connect with SSH to a CentOs server in the cloud that is headless, i.e. I only have the bash terminal at my disposal, unless I connect an additional session (which I think would be wasteful). Thus, I thought that any tips about the screen command in bash would be generic and helpful across the Linux distributions. However, I see your point and will update the question with the circumstances. – Orion Jul 3 '16 at 12:39

Why run seperate screen instances at all. What I think you want to do can be done much more efficientsly (both qua resources and with less typing as follows:)

  1. Start only one instance of screen.
  2. Control-A C

You now have one screen program with two active shells.

You can switch between windows with Control-A number.
You can view which windows are runnign with ControlA "
You can assign a name to the current active window with Control-A A

If you have a few screen which you use consistently you can puyt that in a .screenrc. Example of sunch a file which starts 4 shells at the same time and assigns then easy to remember names:

$ cat ~/.screenrc
vbell off
startup_message off
screen -t ele        0
screen -t OS         1
screen -t A2         2
screen -t Universes  3

And with only one screen running there is no need for screen -ls. Any screen -d and screen -r or screen -x will do.

  • This is perfect, thanks a lot! I did not realise that you could instantiate more windows within each screen session. So much better with the shortcuts. – Orion Jul 3 '16 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.