NAVIGATE

RESOURCES

CHEATSHEETS

INFO

Linux screen command

What is 'screen' tool and how you can use it to increase your productivity and look like a hacker!

What is screen

If you use the terminal to do everything and you want to touch the mouse as little as possible, you should consider installing 'screen': this command line tool divides the terminal interface into many areas and you can work in each of them independently, as they were separate processes. In this way, you can easily switch from one terminal instance to another, by using solely the keyboard.

img
Screen command executed on Debian

As you can see from the image above, you can split the screen into subsections as you want, and execute whatever you need in each of them.

Screen command is based on a massive usage of shortcuts and key bindings, so learn them now! In this article only the most used commands are listed, just to introduce this tool to the basic user. Once installed, you can run it by typing 'screen' on your terminal. A page will show you the name of the programmers and other info about the program, press Enter to quit. Now bash is ready to receive your commands.

Installation

As always, screen installation can be done just by invoking the packet manager from the command line

0
sudo apt-get install screen

or

0
sudo pacman -S screen

You don't need anything else since the installation procedure automatically checks and downloads all the dependencies. Now you are ready to start.

First steps

Launch screen

To launch screen just type 'screen' on the terminal and press Enter one more time.

Create a window

Now that you have entered the screen environment (no changes on the terminal), press Ctrl-a and then press the key c. In this way, you have created a new window inside the terminal. You can press Ctrl-a, then c as many times as you want to create new windows. Note that all those windows have the same name (bash) but they have a number, given automatically, to identify each of them. In general, it can be useful to plan how many windows you need before you perform the next step.

Note that all the spawned windows are now placed 'one on the top of the other': this means that you'll not be able to see all of them until you split the screen into regions. Let's do it!

Split the screen in regions

Now, press Ctrl-a and then Shift-S (pay attention to the uppercase) to split the screen into two horizontal regions, then press Ctrl-a and then Shift-| to split vertically the upper region.

To switch between regions you can press Ctrl-a, then Tab. When you reach the desired region, press Ctrl-a then n to switch to the next window created. Note that if you have more than one region connected to the same window, all the commands written in one of them will be shown in the other ones too.

Change windows title

To change the title of the current window, press Ctrl-a, then Shift-a, then insert the desired title and press Enter; the title will be shown at the bottom of the region. If you want to create a new window, press again Ctrl-a, then c.

Detach windows

Sometimes you may want to detach (suspend from the current terminal) the screen environment. For this purpose, press Ctrl-a then d. In this way, your screen process is sent to the background and you can work on the terminal again. All the operations you were performing on screen are now running in the background and, if you want to look at it, you just have to type 'screen -r' on the terminal or maybe on another one! Yes, screen you launched on a terminal can be detached from that one and reattached to another terminal! However, when you do this, you must set up again your workplace, recreating regions and assigning a window to each of them.

List of shortcuts

  • screen Start screen environment
  • screen -r Resume the previously detached screen instance
  • screen -r Resume one of the previously detached screen instances; if more than one, you have to specify the ID
  • screen -ls List all the screen instances with related ID and status
  • Ctrl-a c Create a new window
  • Ctrl-a n Switch to the next window
  • Ctrl-a p Switch to the previous window
  • Ctrl-a d Detach the current window, going back to the terminal you launched 'screen' from
  • Ctrl-a k Kill (close without any save if you have open files) the window you are working on
  • Ctrl-a Shift-" List all open windows in a screen instance
  • Ctrl-a Shift-S Split the screen into two parts, horizontally
  • Ctrl-a Shift-| Split the screen into two parts, vertically
  • Ctrl-a Shift-A Change the title of the current region
  • Ctrl-a Shift-H Start the screen log: everything you write and is shown on the screen is saved to 'screenlog.0' file. To close and save the log file, just repeat the "Ctrl-a Shift-H" command
  • Ctrl-a Shift-X Close the current region (the window shown in that region is not closed nor killed)
  • Ctrl-a Shift-? Show shortcuts associations
  • Ctrl-a Tab Switch to the next region
  • Ctrl-a ESC Enter the copy mode
  • ESC If working in copy mode, then exit copy mode

Share this page

Whatsapp Facebook LinkedIn Reddit Twitter Mail

Comments

Please, remember to always be polite and respectful in the comments section. In case of doubts, read this before posting.

Posted comments ⮧

Comment section still empty.

INDEX


INFO

vAuthor: Vanadium
vLast Mod: 2024-01-05

STATISTICS

VViews: 174
UpVote: 6
DownVote: 2

CONTACTS


SHARE

Whatsapp Facebook LinkedIn Reddit Twitter Mail

If you liked

🍵
♥