DEV Community

Fred Richards
Fred Richards

Posted on

Nested, Muxed, Screens on the CommandLine

I'm a huge fan of the command line and always have been. If you're like me, you're most comfortable at the keys in a dark terminal session. Most of my day to day work can get accomplished through a terminal, with the rare case of needing a graphical web browser.

As both a network engineer and systems admin, I have a lot going on at any given time. There are two tools I believe we all use, stuff happening in the background, and an organized classification of our work areas, often times separated.

This is a good way to classify projects, environments, testing, coding, you name it. Each workspace has it's own separation. I'm often logged into dozens of servers, iot devices, lab machines, vms, cloud instances. It helps to stay organized.

And I'm not going to log into these resources everytime I swap client machines I'm working behind. I could be using a linux machine, a chromebook, a windows laptop, bastion host, or temporary container. I need stuff to continue to run in the background.

This is where GNU Screen comes in. I've used it for years. How to use screen is a bit out of the scope of this post, but the quick description is that it's a terminal muxer. It takes one ssh session and creates a back-end of many sessions. You can disconnect and leave them running, move to a different client, and re-connect later. This is great for long-running processes like compiling or creating stacks or container environments. Commands are based on a hot-key "ctrl-a". For example, to switch to the next screen session, "ctrl-a n".

Now somewhere on the internet, there's a holy war raging. There are people who prefer tmux, an alternative to GNU screen. Each has their own pros and cons, and for a while I switched from exclusively screen to exclusively tmux. But wait, these are open source tools, can't I use both? The hot-key for tmux is "ctrl-b" and some of the commands overlap. Ie, next-session in tmux is "ctrl-b n".

The diagram shows my new setup. Tmux handles my groups. Screen handles my sessions inside those groups.

Typically I use up to nine sessions in each screen session, so this allows me to have eighteen sessions muxed into one, grouped into two groups. I've found a more comfortable working number is somewhere between 12-15.

my screen nested tmux layout

This is just the tip of the iceberg when it comes to tools. Don't even get me started on mosh, the mobile shell which uses protocol buffers (from Google) to resume roaming sessions.

Discussion (0)