Open In App

screen command in Linux with Examples

Last Updated : 12 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with ‘screen’, the process can be detached from session & then can reattach the session at a later time. When the session is detached, the process that was originally started from the screen is still running and managed by the screen itself. The process can then re-attach the session at a later time, and the terminals are still there, the way it was left. Syntax:

screen [-opts] [cmd [args]]

Options:

  • -a: It force all capabilities into each window’s termcap.
  • -A -[r|R]: It adapt all windows to the new display width & height.
  • -c file: It read configuration file instead of ‘.screenrc’.
  • -d (-r): It detach the elsewhere running screen (and reattach here).
  • -dmS name: It start as daemon: Screen session in detached mode.
  • -D (-r): It detach and logout remote (and reattach here).
  • -D -RR: It do whatever is needed to get a screen session.
  • -e xy: It change the command characters.
  • -f: It make the flow control on, -fn = off, -fa = auto.
  • -h lines: It set the size of the scrollback history buffer.
  • -i: It interrupt output sooner when flow control is on.
  • -l: It make the login mode on (update /var/run/utmp), -ln = off.
  • -ls [match]: It display all the attached screens.
  • -L: It turn on output logging.
  • -m: It ignore $STY variable, do create a new screen session.
  • -O: It choose optimal output rather than exact vt100 emulation.
  • -p window: It preselect the named window if it exists.
  • -q: It quiet startup. Exits with non-zero return code if unsuccessful.
  • -Q: It commands will send the response to the stdout of the querying process.
  • -r [session]: It reattach to a detached screen process.
  • -R: It reattach if possible, otherwise start a new session.
  • -S sockname: It name this session .sockname instead of …
  • -t title: It set title. (window’s name).
  • -T term: It use term as $TERM for windows, rather than “screen”.
  • -U: It tell screen to use UTF-8 encoding.
  • -v: It print “Screen version 4.06.02 (GNU) 23-Oct-17”.
  • -x: It attach to a not detached screen. (Multi display mode).
  • -X: It execute as a screen command in the specified session.

Shortcut keys Options:

  • Ctrl-a + c: It create a new windows.
  • Ctrl-a + w: It display the list of all the windows currently opened.
  • Ctrl-a + A: It rename the current windows. The name will appear when you will list the list of windows opened with Ctrl-a + w.
  • Ctrl-a + n: It go to the next windows.
  • Ctrl-a + p: It go to the previous windows.
  • Ctrl-a + Ctrl-a: It back to the last windows used.
  • Ctrl-a + k: It close the current windows (kill).
  • Ctrl-a + S: It split the current windows horizontally. To switch between the windows, do Ctrl-a + Tab.
  • Ctrl-a + |: It split the current windows vertically.
  • Ctrl-a + X: Close active Split window
  • Ctrl-a + Q: Close all Split windows
  • Ctrl-a + d: It detach a screen session without stopping it.
  • Ctrl-a + r: It reattach a detached screen session.
  • Ctrl-a + [: It start the copy mode.
  • Ctrl-a + ]: It paste the copied text.

Examples:

  • Installation of screen command: To install the screen command simply go to the terminal and type the following command:
sudo apt install screen
  • screen: It will start a new window within the screen.
screen
  • -S: It will start a new window within the screen and also gives a name to the window. It creates a session which is identified by that name. The name can be used to reattach screen at a later stage.
screen -S file
  • -ls: It is used to display the currently opened screens including those running in the background. It will list all the attached as well as detached screen sessions.
screen -ls
  • -d: It is used to detach a screen session so that it can be reattached in future. It can also be done with the help of shortcut key Ctrl-a + d
screen -d 1643
  • Here 1643 is the screen id we want to detach.
  • -r: It is used to reattach a screen session which was detached in past.
screen -r 1643

Note:

  • To check for the manual page of screen command, use the following command:
man screen
  • To check the help page of screen command, use the following command:
screen --help

screen command in Linux with Examples – FAQs

What is the screen command in Linux?

The screen command in Linux is a terminal multiplexer that allows you to create, manage, and navigate multiple terminal sessions from a single console. It is useful for running multiple processes simultaneously without them interfering with each other.

Why do we use screen in Linux?

We use the screen command in Linux to keep terminal sessions running independently of the current terminal window. This is particularly useful for long-running processes, as it allows you to disconnect and reconnect to the terminal session without interrupting the running processes.

How to close a screen in Linux?

To close a screen session in Linux, you can either type exit or press Ctrl+a followed by k and confirm the kill command:

exit

Or:

Ctrl+a k

How to resume screen in Linux?

To resume a detached screen session, use the screen -r command followed by the session ID if there are multiple sessions:

screen -r

If there are multiple sessions, list them first:

screen -ls

Then resume the desired session:

screen -r session_id


Next Article

Similar Reads

three90RightbarBannerImg