Long ago, a very historic unix hacker was surprised to see I don’t know what “Screen” is! Seeing him so excited, I looked into screen. Basically it is a terminal multiplexer/emulator which gives you the facility of multiple terminal over a single terminal screen. Back then, I had just started my career and the tool didn’t seem very essential to me. If I need multiple terminal, I can just open multiple terminal, right! Huh! How naive I was. I didn’t realize the beauty of screen until I had to maintain a production system over a very slow internet connection where I had to first ssh into one machine, from there, ssh into another machine, then do the work. I had to do this for 3-4 terminal just to get going, But that is until I started to use Screen properly. Now I open a single connection and use Screen to emulate multiple terminal. The added advantage is, You don’t loose your ssh session even when your connection goes down, you simply reattach to that session after reconnecting. This is specially helpful when you don’t want to stop your process even if the terminal that spawned the process dies. (You can also use nohup for that).
First install screen:
$ yum install screen
Anyway, here are the screen commands that I use frequently and can help you get started.
1. Start Screen:
You will see some greeting message. You can set it off by putting this line in your $HOME/.screenrc file
OK, now you can see the same old terminal screen where you can do anything that you used to do in your main terminal. But keep in mind that, its not your regular terminal, you are actually in the “Screen” application. So this is your base screen terminal with index 0. You can continue your work with it.
Now, If you want another terminal, on the “Screen” terminal, hit
. You are now in another terminal(this with index 1). To go back to previous terminal, hit
(that is press CTRL-a and then press ‘). you will see an emacs style prompt asking your the index: .
will switch between most resent two terminal.
will directly take you to terminal 1 . Cool! Now you can start as many screen as you want and play around! If you want to list all active screen terminals :
Now that you have the very basics of screen, here comes the most powerful feature: Attaching to a previous screen session and Detaching from an existing screen session.
When you are inside screen, press :
This will detach you from an existing screen session. To connect back to the screen session use:
$ screen -r
It will connect you to the screen session, But what if you have multiple screen? You can see the screen list like this:
$ screen -ls
Now you can use the screen name to reattach:
$ screen -r mysession
But you surely don’t like the screen name which is provided by default. You can provide a screen session name when you created a screen session like this:
$ screen -S mysession
Now that you get the basics and have the feel for it, you can explore more advanced options like cut/copy/paste , history etc.
I’ll leave that on you to explore.