tmux? What is The official verbiage describes tmux as a screen multiplexer, similar to GNU . Essentially that means that tmux lets you tile window panes in a command-line environment. This in turn allows you to run, or keep an eye on, multiple programs within one terminal. Screen A common use-case for tmux is on a remote server where you have a common layout that you always use, and want a way to quickly jump into and out of. An example would be if you’re connecting through a jump server and have other remote SSH sessions you would like to be connected to simultaneously. Similarly, if you have to hop into , you can use tmux to give you access to your shell or a REPL in the same terminal window for a IDE-like experience. Vim This guide will go through the installation and basic usage of tmux to get you up and running. Alternatively, you can just skip all the reading and go straight to the need-to-know commands under the section. Summary of Primary Commands Installation This guide will focus on MacOS and Ubuntu. If you are on CentOS or Amazon Linux, you can use in place of . yum apt-get MacOS Installation The easiest way to get started with tmux on a Mac is to use the package manager. Homebrew . If you don’t have Homebrew installed yet, open either Terminal or and paste the below command: 1 iTerm /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" . Once Homebrew is installed, you can use to install tmux: 2 brew brew install tmux . Confirm that it installed by checking the version : 3 (note the uppercase _V_ ) tmux -V Ubuntu / Debian Linux Installation Installation for Ubuntu is similar to Mac, except that we will be using the package manager that comes pre-installed. Note that we will have to run as . This is because a user account won’t have enough privileges to install tmux, so will allow us to install it as superuser. apt-get apt-get sudo sudo . Update to make sure we are on the latest and greatest: 1 apt-get sudo apt-get update . Install tmux: 2 sudo apt-get install tmux . Confirm that it installed by checking the version: 3 tmux -V Getting In & Getting Out tmux is based around sessions. To start a new session in tmux, simply type in your terminal. Once you are in tmux, the only thing that will be visibly different is the ever-present green bar at the bottom . tmux new (see Getting Fancy with Custom Themes section for customization options) Default view after starting new session To get out, you can type if you’re in a single pane, and you’ll return from whence you came. exit An important note is that is not the only way to get out, and usually not the best way. For that we have . However before we get to that, we first have to cover the prefix… exit detach Using Prefix All commands in tmux require the prefix shortcut, which by default is . We will be using the prefix a lot, so best to just commit it to memory. After entering you can then run a tmux command, or type to get a tmux prompt. ctrl+b ctrl+b : “ ” to get tmux command prompt ctrl+b : When entering the prefix, tmux itself will not change in any way. So, if you enter and nothing changes, that does not necessarily mean you typed it wrong. ctrl+b Attach, Detach & Kill As mentioned, a better way to get out of a session without exiting out of everything is to the session. To do this, you first enter the prefix command and then the detach shortcut of : detach d ctrl+b d This will detach the current session and return you to your normal shell. However, just because you’re out doesn’t mean your session is closed. The detached session is still available, allowing you to pick up where you left off. To check what sessions are active you can run: tmux ls The tmux sessions will each have a number associated with them on the left-hand side . This number can be used to attach and get back into this same session. For example, for session number 3 we would type: (zero indexed as nature intended) tmux attach-session -t 3 or we can go to the last created session with: tmux a # Naming Sessions Now we just rely the session numbers, but it would make our life much easier if we give our sessions names based on their intended use. could To start a new session with a specific name we can just do the below: tmux new -s [name of session] With named sessions in place, now when we do we see the session name instead. Likewise, we can then attach a session by using the name: tmux ls tmux a -t [name of session] Note that we substituted for to help save on keystrokes. a attach-session Managing Panes In a GUI desktop environment, you have windows. In tmux, you have panes. Like windows in a GUI, these panes allow you to interact with multiple applications and similarly can be opened, closed, resized and moved. Unlike a standard GUI desktop, these panes are tiled, and are primarily managed by tmux shortcuts as opposed to a mouse . To create a new pane you simply split the screen horizontally or vertically. (although mouse functionality can be added ) To split a pane horizontally: ctrl+b " To split pane vertically: ctrl+b % tmux split horizontally, with lower pane split vertically You can split panes further using the same methodology. For example, in the above screenshot, the screen was first split horizontally using and then split vertically within the lower pane using . ctrl+b " ctrl+b % To move from pane to pane, simply use the prefix followed by the arrow key: ctrl+b [arrow key] Resizing Panes Lets say we need a little extra breathing room for one of our panes, and want to expand the pane down a few lines. For this, we will go into the tmux prompt: ctrl+b : From there we can type followed by a direction flag: for up, for down for left and for right. The last part is the number of lines to move it over by. resize-pane -U -D -L -R As an example, if we are in the top pane and want to expand it down by 2 lines, we would do the following: ctrl+b :resize-pane -D 2 being entered resize-pane -D 2 Getting Fancy with Custom Themes Customizing tmux is done primarily through the file. .tmux.conf Creating a custom theme from scratch gets pretty time consuming to get dialed in. As such, best to just use a pre-made theme instead as a jumping-off point. An especially good collection can be found on Jim Myhrberg’s repo. tmux-themepack Simply pick the one you want and copy the config into and then source it with . ~/.tmux.conf tmux source-file ~/.tmux.conf tmux running with 3-pane layout Cyan theme Additional Resources The possibilities here are just the tip of the iceberg. If you are ready to go even further down the rabbit-hole, the below links should help fill the gaps. by Cheatsheet MohamedAlaa by tmux-themepack Jim Myhrberg by The Tao of tmux Tony Narlock by Oh My Tmux! Gregory Pakosz Summary of Primary Commands Questions/Comments/Other? Drop me a line via GitHub or LinkedIn
Share Your Thoughts