How to use GNU SCREEN - the Terminal Multiplexer - linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so in this tutorial I'm going to show you the basics of the screen utility so let's get started okay so screen is a terminal multiplexer and to get it I'm just going to open up a terminal and as on one Ubuntu i canjust sudo apt - get install screen but if you're on fedora you can just use yum install or whatever package manager you're using screen is very prevalent so you should be able to find it in any repository for any distro so the simplest way to start a screen session is simply just by typing in screen and we have this message which we can get rid of by using the spacebar or 10 and we're now in our first screen session so let's just echo out first screen session now the first thing that we're going to do is detach from this session now by default every command in screen is prefixed by ctrl + a so if we hold ctrl + a and then press D to detach you can see that we're now detached from our screen session so now the route side of our screen session we can type in screen - LS and you can see we have one session the word detached from and if you look at the first part here this is the PID of our screen session so if we just type in PS - E and we want to pipe the output of that interbred and we want to grep for 1 - 1 0 8 you can see that that is a screen session so this title for our screen session is not very descriptive so let's create a new screen session and give it a new name so we can just type in screen - capital s and then our name so let's just call it second screen session and just hit enter to create that and we're now dropped into one new screen session so let's just write something in here so echo second screen session and to detach from this screen session same again hold control press a and then press D and we've now been dropped out of that screen session so if we type in screen - LS you can see that we have our two sessions so the first one that we created and this is our second one which we named so second screen session so now let's reattach to our first screen session which is this one here and to do that we just type in screen - R - reattach and we can either enter in the PID or part of the PID or part of the title so I'm just going to enter in 1 - 1 because that is the first part of this PID and if I had have entered in 1 2 it would be confused with our second screen session but that should be sufficient and if we just hit enter you can see that we're now back in our first screen session so I'm just going to detach from that control a and then D and let's just attach to our second screen session which is this guy over here but this time we are just going to type in SEC so that's just the beginning of this so second and just hit enter and we're now in our second screen session and let's detach from this screen session again so hold control press a and then D okay so let's just clear the screen and get a listing of our screen session so screen - LS okay so let's get rid of this first session that we created so to do that we can just type in screen - capital X to send a command to that session and then - capital s and we enter in the name of the session so I'm just going to enter in the PID so it's one two one zero eight and the command that we want to send is quit so qit enter and if we just type in screen - LS you can see we no longer have our first session and we only have the second session okay so let's reattach to our second session so screen - R - reattach and we don't really need to drop in a name because we're you have one session and screen is smart enough to work that out so let's just hit enter and as you can see we're back in our second screen session now we can kill this screen session from within this screen session by holding ctrl a and then pressing K and it says really kill this window so we're just going to hit yes and as you can see we've been dropped out of our screen session and if we screen flash LS we have no sessions listed now ctrl a and K is not strictly for killing screen sessions but it's for killing windows within a screen session and as we only had one window within that session a byproduct of that was killing the screen session itself because there are no windows within it so let's recreate that screen session again so - capital S let's call it second screen session but this time what we're going to do is I'm just going to echo 0 within this window because we're actually within a window within our screen session right now and what I'm going to do is create a new window so to do that we're going to hold ctrl a and press C and now we have a new window so I'm just going to echo one into this window and to get a listing of Windows that we have we can hold ctrl a and press W and as you can see I have two windows open now to move forwards and backwards through windows we can use ctrl a n for next or control a P for previous and these loop around so I'm just holding ctrl and pressing end continuously now and as you can see we're looping through all two windows and the same goes for ctrl a and P we're just looping backwards through them so now if I hold ctrl a and press K to kill a window it's going to kill windows 0 just say yes and as you can see it's killed windows 0 but we're still within our session so if we detach from this now so ctrl a and D and then list our sessions so screen - LS you can see that we still have our session so we can reattach to that so screen - are and as we only have one session we can just screen we'll just reattach to that one and if we just list the windows we've only got one window here so let's just create a couple more windows so hold ctrl press a and then press C and I'm just going to do that a couple of times just to create a couple of windows and if we do ctrl a and then W you can see that I have got seven windows open now so as we know if we hold ctrl a and K we can kill a single window so we killed Windows six just then but we're still in our session so to kill all of the windows and end the session we can hold ctrl a and press backslash and then it says really quit and kill all your windows just say yes and we've been dropped out of our session and if we screen - LS we no longer have any sessions running okay so let's create another session so screen and - capital s let's just call it third screen okay so now we're in our session I'm just going to echo out 0 into this window and create a couple of windows so control AC to create and I'm just going to echo out one in this window and then control AC and echo out two and then control a and C and echo out three into this window so rather than using control a N or P to just scroll through our windows like this what we can do is we can jump to those numbers so if you notice in front of the window titles we've got these numbers so 0 1 2 & 3 so we're now on screen 0 so I'm just going to open up that list again so control aw and let's go to 1 so control a just press 1 and we can do that too - so control a press to control a let's go to 0 control a and 3 and as you can see we can just jump to whichever window we want so we just need to know what window number they are now there's another list that we can open of our windows and that is by holding ctrl a and then you need to press double quotes so for me it's shift and then 2 to get double quotes we can actually select the window from here so let's just jump to window 2 and as you can see we're in window 2 now I'm going to open that list up again and as you can see under the names they're all named bash and that's really non-descriptive for us so we don't really know what's on those windows we just have to go to it and hope that it's a window we wanted so we can actually rename our windows so let's rename window 2 which we're currently on and we can do ctrl a and then shift a for capital a and we can set the window title here so let's change it from bash to window 2 and hit enter and now if we hold ctrl a and press W to get a window listing you can see our second window here so window 2 has now been called window 2 now what if we wanted to display two windows both within the same terminal what we can do is we can actually split our terminal into multiple panes so to do that let's just split it vertically so straight down the center we can hold ctrl a and then hit the pipe symbol so for me that's shift and backslash to get a pipe and as you can see we now have two panes so we have a left and a right pane now as you can see the cursor is on the left-hand pane and to get it to move to the right-hand pane we can just hold ctrl a and then press tab so we can tab through our panes you may also have noticed that on the second pane there isn't a command prompt and there's no window title at the bottom and that's because we don't actually have a window open here so all we need to do is open a window here so I'm just going to hold ctrl a and press W to bring up the list again and let's just open windows 0 here so ctrl a and then just press zero and as you can see windows zero is now open on our right hand pane we can also split panes horizontally so hold ctrl a and then shift s for a capital S and as you can see we've split our paint horizontally so I'm just going to jump down here so ctrl a and tab and the cursor is moved to our new pane and let's just open up window one here so control a1 and as you can see this is our window one we can also open the same windows in multiple panes so let's open window 0 in our bottom pane here so control a and then 0 and if we start typing so let's just echo this is window 0 you can see that everything we typed in this pane showed up in this pane which is also open on windows 0 now let's just say that we wanted to get rid of this pain we can close it by holding ctrl a and then shift X so as you can see we got rid of that pain but we still have windows 0 and we can confirm that by opening up a listing of the window so control aw and you can see we still have windows 0 and everything that we typed into windows 0 is still here in windows 0 ok so one thing to note is if we detach from the screen now so ctrl a and then D and let's reattach to its low screen flash are our window panes have disappeared but if we just list our windows you can see that all of our windows are still there so let's just split the screen so split it vertically so ctrl a and the pipe symbol and let's just split that horizontally so ctrl a shift s and let's use our selectable list to put a window here so ctrl a and then double quotes and let's just put window 0 up here ctrl a tab down to the next pane and control a double quotes let's put window 1 there control a tab just as shift over to this one and let's just put let's put window to here so we can also lock our current screen session by using control a and pressing X and as you can see our session is now locked and it requires a password now the password by default that it requires is your login password so the login password for Linux lecture so I'm just going to enter that to get back into my session and as you can see we're back into the session and we're on window too now another thing that you can do while you're within the session is if you hold ctrl a and press T you can get the time to come up as well as the load average for your machine to come up as well okay so now let's just kill this screen session so ctrl a backslash and yes we want to kill it and screen - LS we have no screen sessions currently running now another thing that you can do with screen is you can actually run commands with screen without popping up a screen session so what I'm going to do is I'm just going to write a quick Python script so this will call it counter top py so I'm just going to start by importing time and then just put a quick little for loop so for I in range let's just say 5 make this short we're just going to print out the time so time dot C time and time time and then we're just going to get this to sleep so time dot sleep sleep for one second ok so what this is going to do is it's just going to grab the time so this is the time in seconds and then I'm just converting it here into something that's readable for us and it's just going to run this five times once a second kind of thing so I'm just going to save that and let's just run it so python counter and as you can see it's just printing out the time every second for five seconds there we go so to run that with screen what we can do is type in screen - D fit attached and then - M and we need Python for that so Python and counter so that's what we're going to run and let's just hit enter and let's just attach to it so you can see it's running and then it dropped us out of the screen session so if you're going to run something with screen like that once whatever you're trying to run has completed the screen session terminate so we can just check that as well by screen - LS and we have no screen sessions running so that's just one thing to bear in mind whereas if we opened up our own screen session so screen - are whoops sorry so if we just open a new screen session so screen let's just type in screen and we run the same thing again so Python counter con type today and as you can see we're still in the screen session and the program has finished running so ctrl + D to detach and we're now outside of that screen session so that's just one thing to bear in mind if you are running a detached screen session and you're running something within it then it will terminate itself once whatever you're running has finished ok so there's just a couple more things I want to show you about screen and that is if you hold ctrl a and then press the question mark you can bring up the key bindings so if you forget anything you can just find it here and the other thing is that you can actually enter commands in directly without using the key bindings so I'm just going to split this window vertically so ctrl a and then pipe and I'm just going to tab over to the new pane that we just created and then open up the key bindings so ctrl a and for me shift forward slash to get question mark and I'm just going to use remove when I find it there we go okay so remove just to remove this pane here so to do that I can actually type in remove and the way I can be able to type in remove is hold control a-and on my keyboard shift semicolon to get the : so ctrl a colon and then just type and remove and it does the same thing as holding let me just open up that again so just create a new pane it does the same thing as ctrl a shift + X to kill the pain so you can type them in and the way you can find out what they're called is ctrl a shift forward slash for me so ctrl a question mark so that's brought us to the end of this tutorial on screen I hope you found it useful if you did please don't forget to subscribe you can also follow Linux leach on facebook twitter and google+ and thanks for watching goodbye
Info
Channel: Linux Leech
Views: 74,814
Rating: 4.9791427 out of 5
Keywords: linux screen terminal multiplexer, terminal multiplexer linux, terminal multiplexer, arch linux terminal multiplexer, terminal multiplexer mac, gnu screen, terminal multiplexer ubuntu, linuxleech, how to split terminal screen on linux, screen, screen command linux, how to split terminal screen, screen command - linux tutorial, screen command, screen commands, screen command unix, how to split terminal screen on mac, screen command in linux, linux desktop, screen utility
Id: I4xVn6Io5Nw
Channel Id: undefined
Length: 18min 30sec (1110 seconds)
Published: Mon Oct 03 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.