[PLUG] A question about using 'screen'

King Beowulf kingbeowulf at linuxgalaxy.org
Wed Jan 12 02:22:32 UTC 2022


On 1/11/22 11:01, Rich Shepard wrote:
> A few nights ago I used screen for a very log running task. The man page
> tells me, "... When screen is called, it creates a single window with a
> shell in it (or the specified command) and then gets out of your way so that
> you can use the program as you normally would. Then, at any time, you can
> create new (full-screen) windows with other programs in them (including more
> shells), kill existing windows, view a list of windows, turn output logging
> on and off, copy-and-paste text between windows, view the scrollback
> history, switch between windows in whatever manner you wish, etc."
>
> When I used it after screen started the command it returned me to the shell
> prompt, $. Since then, when I've started a screen session with the command
> to run it gives me a couple of line feeds and no prompt.
>
> What might I be doing incorrectly?
>
> TIA,
>
> Rich
>
The screen manpage a hefty tome to wade through.  basic 'screen' usage
is pretty simple.  I've switched to tmux as I find its commands a bit
simpler to use...or maybe remember....

start a "blank" screen, just so

$ screen

...now do stuff...

CTRL-a d  to go back to original shell (detached) To list sessions,
detached, that are running stuff

$ screen -ls
There is a screen on:
    18112.pts-3.gandalf    (Detached)
1 Socket in /home/beowulf/.screen.

To reattach, either explicitly

$ screen -r 18112[.pts-3.gandalf]

(the .pts etc is usually optional) or if only 1 screen running

$ screen -R

to open it up to see the goings-on. When attached to a screen typing
"exit" at the prompt will terminate.  If you start screen with the program:

$ screen htop

when the program exits, screen will terminate.  Now lets give screen
something human readable, and start program 'htop':

$ screen -S my_htop -t stuff htop

"stuff" is now the title name in the status bar to label what the screen
is doing "my_htop" to help remember when running multiple screens. 

$ screen -ls
There is a screen on:
    18573.my_htop    (Detached)
1 Socket in /home/beowulf/.screen.

To re-attach
$ screen -r my_htop

There are a bunch of bells and whistles, $HOME/.screenrc customizations,
split windows, yada yada. For example, my .screenrc has for the status:

----------
# detach on hangup
autodetach on

# don't display the copyright page
startup_message off

# emulate .logout message
pow_detach_msg "Screen session of \$LOGNAME \$:cr:\$:nl:ended."

# make the shell in every window a login shell
#shell -$SHELL

defscrollback 2000


# improved status:

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=
kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}
%m-%d %{W} %c %{g}]'

----------
among other things I've long since forgotten how to do.  As Randy
mentioned "screen -L [-logfile <log_file>]" in case you need to figure
out why screen terminated etc.

Anyway, I'm all into tmux these days:

tmux new-session -s <name> <program>
tmux ls
tmux attach-session -t <name>
tmux kill-session -t <name>

C-b d detaches a session.  For example:

tmux new-session -s <session_name> -n "window_title" "program_name args"
2> $/path/my_tmux.log

-Ed





With either screen or tmux, you can start something, detach and then ssh
in from another computer to check.  Because sometimes to lazy to roll
the chair over 3 feet in my office!








More information about the PLUG mailing list