Check out a free preview of the full Introduction to Bash, VIM & Regex course

The "Screen" Lesson is part of the full, Introduction to Bash, VIM & Regex course featured in this preview video. Here's what you'd learn in this lesson:

James introduces screen, which allows multiple virtual windows in Unix.

Preview
Close

Transcript from the "Screen" Lesson

[00:00:00]
>> James Halliday: I really like Screen. It's a very nifty little tool. Like here, I can just show you the screens that I'm running on my system right now. So I'm running like three screens to run different daemons and things, like Secure Scuttlebutt. And show you my WiFi screen. So this is running some command line WiFi stuff, cuz I don't like the little applets where you gotta click on WiFis and whatever so I just made it into my wifi with some command line tools.

[00:00:31]
Another really useful thing that you can use for screen is if you ssh into a server, you can like kinda have stuff running, and then you can sort of attach to it later. So here, I can login to my command line IRC client that's running. And there it is, it's just running, doing its thing.

[00:00:50]
Now I can detach from this, so I do control AD, whoops. And now, it's still running, but I'm not looking at it anymore, and I can logout. If I log in again it's still gonna be running. So it's sort of like a way that you can just leave something to do its thing, and you can check on it later, or whatever.

[00:01:11]
So, if you're on a Linux system, you generally don't have this by default unless someone already installed it. I don't know on Mac, if you have to brew install or anything, if someone could check that really quick, it'd be handy. If you just type screen, what happens?
>> Speaker 2: Yeah, I got it.

[00:01:28]
>> James Halliday: Okay, cool, so I guess you might have it on Mac already, but on Linux, you might have to install it. So if you just type screen, it's just gonna look like, I guess it does that now, that's weird. But it's going to drop you into a shell, which you can either do control-b or type exit to get out of.

[00:01:56]
After a page of spam, I guess that's what it does. If you want to create a screen that has a name, though, because by default if you just do a screen maybe it only does that when I'm in a low res. Let me see. I don't know, it's just always annoying like that.

[00:02:11]
So, if you do that, I can list out everything. You can see that it doesn't have a name now. If you want to give your screens a name, which I recommend, because it's easier to keep track of them, you can do screen, -S and then give it a name like wow or whatever.

[00:02:33]
Now if you do screen- list we see that a screen called whatever is attached, and all the other screens are detached.
>> James Halliday: So screen-list is how you can see what all of the screens that are running on your system are.
>> James Halliday: And so the first thing that you can try once you're running a screen like I'm running this screen, is do control a.

[00:03:05]
As, like, one thing, like hold down Control and hit the A key, no, what up, and hit the D key. And that will detach from the screen. And then to attach back to that same screen, you can do screen- x and then give it the name. So I called that screen whatever, so now I can reattach with that.

[00:03:31]
And if you see, I'm back exactly where I left off. So again, it's Ctrl A, then D, and then Ctrl+X and the name to go back. After you create a name to screen with screen -S and then the name.
>> James Halliday: The steps.
>> James Halliday: Yeah?
>> Speaker 2: Does screen load your bash profile?

[00:04:07]
I'm getting errors trying to parse a function, for instance, from my batch profile.
>> James Halliday: It should load your bash profile, yes.
>> James Halliday: It should be pretty similar to if you open a new terminal. It would do the same steps, more or less. Another fun thing to try, once you've got screen running, is you can create a new window with Ctrl A C.

[00:04:37]
So I can show you what that looks like. So, Ctrl A C, and now I'm on a new window, which is like a new terminal. You can do, watch dash n1 date on that window. And if you want to switch between windows, you can do Ctrl a n to go the next one, Ctrl+a+p to go to the previous one.

[00:04:59]
So it's sort of like you have a list of these windows that wraps around and you can kind of switch between them.
>> James Halliday: And if you want to exit from a screen, you can type Ctrl d. Or you can type exit, and it will close that window. And once all of the windows are closed on a screen, then the screen, it says the screen is terminating and then that screen doesn't show up on screen dash list anymore.

[00:05:38]
>> James Halliday: So if you want, so a really fun, well. So screen is really good for running little servers and things. You could run things in a while true do, your server program done loop inside of a screen and then detach from it. It's also really good if you want to run a command line IRC client, because then if you have a server, you can just have that running all the time and connect to it, like I have over here.

[00:06:07]
You can also use this program called Mosh, instead of SSH. And it will automatically reconnect for you. If you go on a different WiFi, it's seamless. And then just have your IRC client running all the time. And it's like, you don't have to, someone wants to message you, they can, you'll see what they had to tell you when you're away.

[00:06:36]
That's more or less all that we need to do to play with screen. If you want, in the notes, I have a little test server if you wanna play around with getting that to run inside of a screen. And then you can leave it running on your system.

[00:06:55]
And that is all that I have for the bash workshop.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now