How To Use DVTM and Dtach as a Terminal Window Manager on an Ubuntu VPS
This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
- Upgrade to Ubuntu 14.04.
- Upgrade from Ubuntu 14.04 to Ubuntu 16.04
- Migrate the server data to a supported version
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
As you begin to work with multiple remote servers, the number of terminal sessions that you have open can begin to feel overwhelming. There are many times, for instance when compiling code, when your terminal is taken up by a long-running process. To get around this and avoid having to connect with a new SSH session to continue working, terminal multiplexers were invented.
Terminal multiplexers allow you to manage multiple terminal windows within a single “master” session. They allow you to easily arrange and interact with windows in a way that is somewhat similar to the way a graphical window manager does. The two most popular tools for this are GNU
screen and the
In this guide, we’ll discuss a different approach. While the other two options are good for many people, they are a bit more heavy duty than most users need, and lack some nice presentation. To address these issues, we will show you how to use a combination of
dvtm, a dynamic virtual terminal manager, which will handle window management, and
dtach a utility that allows you to detach sessions for persistence. This is a much lighter-weight solution and will be a better fit for some people.
We will be covering the installation and usage of these on an Ubuntu 12.04 VPS instance, but most distributions should be able to use these steps with a bit of modification.
Install the Components
The first step in doing most things on a Linux server is making sure you have the tools you need.
In our case, we’ll have to download and install both
dvtm. Fortunately, the Ubuntu 12.04 repositories have both of these utilities available. We need to refresh our local package index and then we can install what we need:
sudo apt-get update sudo apt-get install dvtm dtach
That’s all we need! We can now start exploring how each of these tools work.
How To Use the dvtm Terminal Manager
dvtm terminal manager is a window manager that attempts to emulate some of the functionality and properties that are loved by users of graphical tiling window managers like
xmonad, etc. It allows you to organize windows easy and manipulate your screen space to fit your needs.
To start a
dvtm session, you simply need to call it from the command line:
─[demouser@dvtm: ~ #1]──────────────────────────────────────────────── demouser@dvtm:~#
As you can see, you now have a new terminal session, but there is a header above it. This header is basically a window title bar. It tells you the session that it is managing and the window number.
The first thing you need to know is that all
dvtm commands start with a “mod” key sequence. When you hit this sequence, it signals to
dvtm that it should start listening and intercept the next key press.
By default, the mod sequence is “CTRL-g”. So each of the commands for
dvtm have the format of:
Basic Window Management
Let’s jump right in and start working with multiple windows. The first sequence you will learn will allow you to create a second window:
You need to hold the “control” key, hit the “g” key, and then release both of those keys and press “c”. You will see your environment split vertically like this:
──[demouser@dvtm: ~ | #1]──────────┬──[demouser@dvtm: ~ | #2]────────── demouser@dvtm:~# │demouser@dvtm:~# │ │
As you can see, you now have two windows! If you type some characters, you will see them appear in one of the windows. To switch which window has focus, type:
CTRL-g j # Cycle forward through windows CTRL-g k # Cycle backward through windows
If you would like to jump to a specific window, you can do so by referencing its window number:
CTRL-g [window #]
For instance, to move focus to window 3, we could type
To destroy the window that has focus, type:
To destroy all windows and end your
dvtm session, type:
Adjusting the Tiling Layout
As you create more windows, you’ll notice that that, by default, one area remains larger, while additional windows are stacked on one side. This is due to the tiling layout.
By default, the windows are laid out in what is called a “vertical stack” tiling layout. This creates one “master” window, and all of the other windows split the remaining space.
There are other layout options available though. Create four or five windows and start some programs in some of the windows so that you can tell them apart.
To cycle through layouts, use this sequence:
By default, the layouts that you can cycle through, in order, are:
- vertical stack: The default layout. The master window is on the left, all other windows share the space on the right.
- grid: All of the windows attempt to take up equal space in the windowing area. There is no relevant master window (it is technically the upper-left space).
- bottom stack: The master window is on the top half of the screen. The remaining windows occupy the bottom half.
- fullscreen: Maximizes the currently focused window. You can cycle through each window as usual in a maximized state.
You can continue to cycle through these layouts with the “space” key, but you can also reference them individually using specific key sequences:
CTRL-g t # Switch to vertical stack CTRL-g g # Switch to grid CTRL-g b # Switch to bottom stack CTRL-g m # Switch to fullscreen
To make the currently focused window the new master window, type:
If you use this on the current master window, it will simply swap it with the next window (clockwise).
Manipulating your Windows and the Windowing Area
While these features are useful, sometimes you need some additional functionality.
For instance, you may need to adjust the size that the master window takes up. To do so, you can use these keys:
CTRL-g l # Increase master window space CTRL-g h # Decrease master window space
This means that you can adjust your screen real estate based on the task at hand.
Sometimes, you won’t need to deal with a window for awhile, but you still need to have it available. In traditional windowing systems, you would minimize the window, which allows you to get it out of the way temporarily.
The same thing is possible with
dvtm. Focus on the window you wish to minimize and then type:
This will minimize the currently focused window.
This is actually a toggle function. You can still easily cycle through your windows and select minimized windows with
CTRL-g j and
CTRL-g k or by referencing it by number (
CTRL-g #). To restore the window, just select it again and hit
CTRL-g . again.
The ability to cycle through minimized windows is a great feature because it allows them to be manipulated and referenced. However, sometimes you only want to cycle through the windows that are currently within the windowing area.
To accomplish this,
dvtm includes another set of cycling commands that only affect windows that are not minimized. So if you have windows 1-5, with 2 and 4 minimized, these would cycle through windows 1,3, and 5:
CTRL-g u # Cycle forward through un-minimized windows CTRL-g i # Cycle backward through un-minimized windows
One additional command that may come in handy occasionally is the ability to send keyboard output to all of your terminal windows simultaneously. You can accomplish this with a toggle that
This will send all output from the keyboard to each individual window. This will continue until you issue the command again to turn this feature off.
How To Use dtach to Make your Sessions Persistant
All of this functionality within
dvtm is great. It allows the application to be more focused than
tmux and concentrate on its strengths. However, because of this, it is limited to window management.
One feature that many users want in a terminal multiplexer is the ability to have persistent sessions. This means the ability to detach from your session and leave the windows, and anything in them, running. Later on, you can reattach to the session to continue working.
dvtm does not have this feature by design, it works great with other tools that are solely focused on providing detach-ability. One of these tools, called appropriately “
dtach”, is perfect for our purposes.
First off, exit your current
dvtm session if you haven’t already. You can type
CTRL-g q if you don’t need to save any work.
Now, we can start a
dtach session. We need to pass a command like this:
dtach -A /tmp/dvtm -r winch dvtm
Let me explain what’s going on here. First, we call the
dtach command itself. This should be self explanatory.
- -A: The uppercase “A” flag attaches to the existing specified session if it exists, otherwise, it creates a new session and attaches to it.
- /tmp/dvtm: This is the socket that
dtachwill use to store and pass information. The permissions of this socket will determine who can connect, so if you want the session to not be usable by other users on your server, place it somewhere that they can’t reach.
- -r winch: This specifies the redraw method. In order for our session to display correctly after reattaching, we need to tell
dtachto send the WINCH signal to the program.
- dvtm: This specifies that once the session is started, we should launch
If you type in this command, a
dvtm session will be started within a
dtach session. It will look exactly the same as your normal
The only difference is that you can now detach from the session, leaving all of your windows running. To do this, type:
To get back to our session after we’ve detached, we can simply call the same command again.
Because the command to start and to reattach to a session is the same, and because the command is a bit cumbersome, we can create an alias which will let us manage this effortlessly.
Open your shell’s configuration file with your text editor:
At the bottom, add an alias so that you can easily start or access your sessions with one word. For example, I’m choosing the sequence “wm” (for window manager) in my configuration:
alias wm="dtach -A /tmp/dvtm -r winch dvtm"
Save and close the file. We can source the file now to get our changes:
Now, when we type
wm, we will create a
dtach session if one does not exists, and start
dvtm within. If a session does exist, this command will simply reattach to the session.
As you can see, by using
dvtm to manage your windows and
dtach to add persistence, you can set up a very useful environment that will allow you to work efficiently with multiple windows. For many users, this provides all of the functionality they need, with better window management layouts than either
tmux. Consider trying it out on one of your servers to see if this is a multiplexing solution that fits your needs.