Sean's i/o Stream


Making screen work for you

  • January 03, 2009
  •   category: linux
  • tags: linux, screen, multitasking

One of my all time favorite tools for Unix and Linux is screen, anybody who spends any amount of time on the command line and managing remote machines will at one point or another will end up with a screen that looks like this.

Welcome to terminal city

This leads you to the almost unavoidable problem of having to open multiple terminals to the same servers and having to search for them in your jumble of open windows. So that is the first benefit you can reap, less open terminals, and less open terminals per remote machine.

Once you start to see the usefulness of screen as an efficient way to manage your terminals you can start to leverage some more features of screen and even modify the key bindings to suit you style or add some helpers to the mix. First customization I recommend is adding the hardstatus line.

hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR} (%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}] %{=b C}%{g}[%m/%d %c%{g}]%{W}'

# F7/F8 to turn the status bar off/on
bindkey -k k7 hardstatus alwayslastline
bindkey -k k8 hardstatus alwaysignore

This gives you a a status line with the hostname, open terminals in the current screen session, load, and the date time.

Welcome to terminal city

This combined with the ability to name your individual sessions ( Ctrl-c + A) makes for a quick little dashboard of various activities you are bouncing between. This opens up some possibilities and if your are like me you might want to set the session title dynamically so that if actually reflects the current program in use, cool idea but a little less friendly to execute, I have see some individual applications and a suggested solution for any programs by using a combination of .bashrc, .vimrc and screen but certainly nothing bulletproof, send me a message if this has changed or if you have any good suggestions.

My favorite and orginial reason for using screen is the ability to start some work on the server and disconnect, or if you are lucky enough loose your internet and become disconnected, and then be able to login again and resume that same session without missing a beat or having all your sessions disconnected. This one is easy, just start screen -R to reconnect to any existing session, if there are more than one, the error/warning is helpful enough to get you sorted.

Migrated: from blogger 03-July-2014

Back to Top