Pages

Sunday, February 23, 2014

[Linux] Some tips for screen

In my opinion, screen is like a CLI-version VNC or RDP, which means you can log in your previous window again using only ssh session.

Screen is especially useful if you connect the server via SSH and need to run a time-consuming process.  Just open a window, running the process on that window, then you can leave and log into the same window to continue you work.

In this post, I use 'window' rather than 'screen' to give you a clear image.  But technically, they are 'screen's by definition.

Show the window list
screen -ls

Create new window with given name
screen -S [window-name]

Attach to an unattached, or log in if it is attached, window
screen -r [window-name]

Attach to an attached window (multiple log in the same window)
screen -x [window-name]

Detach (leave but not kill) a window
screen -d [window-name]

Kill a detached window
screen -X -S [session # you want to kill] quit

Leave (and kill) the current window you are on
exit

Check whether you are on any window
echo $STY

if is is 'null', then you are not on any window.  You can also edit your shell to show that in your prompt:
~/.bashrc
# just showing that you are using screen or not if [ -n "$STY" ]; then export PS1="(screen) $PS1"; fi # or showing the window name # if [ -n "$STY" ]; then export PS1="($STY) $PS1"; fi

You can also use hot-keys, which I do not recommend to the beginners.  Check the reference for more detailed information:

References
http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
http://www.bartbania.com/index.php/linux-screen/

No comments:

Post a Comment